DestructionModule.lua
DestructionModule.lua
PhysicsService:CollisionGroupSetCollidable(cloneCollisionGroupName,
cloneCollisionGroupName, false)
end
function module.FlewUpParts(v, duration)
if v:IsA("BasePart") and v.Parent and v.Parent:IsA("Model") then
local parentModel = v.Parent
if not parentModel:GetAttribute("IsBeingDestroyed") then
parentModel:SetAttribute("IsBeingDestroyed", true)
if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)
clone.Anchored = false
clone.CanCollide = true
clone.Transparency = 0
clone.CollisionGroup = cloneCollisionGroupName
local smoke =
game.ReplicatedStorage.VFX.SMOKE:Clone()
smoke.Parent = clone
smoke.Color =
ColorSequence.new(clone.BrickColor.Color)
wait(0.0002)
for _, v in ipairs(clone:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name ==
"SMOKE" then
if v then
v.Enabled = true
v:Emit(20)
print("Emitting particles
from", v.Name)
end
end
end
clone.AssemblyLinearVelocity = Vector3.new(0,
math.random(50, 80), 0) +
clone.CFrame.RightVector * math.random(-
30, 30) +
clone.CFrame.LookVector * math.random(-
30, 30)
clone.AssemblyAngularVelocity =
Vector3.new(math.random(-8, 8), math.random(-8, 8), math.random(-8, 8))
clone.Parent = workspace
task.delay(duration - 1, function()
fadeOutTween:Play()
fadeOutTween.Completed:Connect(function()
clone:Destroy()
end)
end)
end
end
task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end
parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end
if parentModel:GetAttribute("Destroyable") then
v.Anchored = true
v.CanCollide = false
v.Transparency = 1
v:SetAttribute("Destroyable", false)
task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") and p ~= v then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end
v.Anchored = true
v.CanCollide = true
v.Transparency = 0
v:SetAttribute("Destroyable", true)
parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end
if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)
clone.Anchored = false
clone.CanCollide = true
clone.Transparency = 0
clone.CollisionGroup = cloneCollisionGroupName
clone.BrickColor = BrickColor.new("Really
black")
local sparks =
game.ReplicatedStorage.VFX.FireSparks:Clone()
sparks.Parent = clone
local smoke =
game.ReplicatedStorage.VFX.SMOKE:Clone()
smoke.Parent = clone
smoke.Color =
ColorSequence.new(clone.BrickColor.Color)
wait(0.0002)
for _, v in ipairs(clone:GetDescendants()) do
if v:IsA("ParticleEmitter") and v.Name ==
"SMOKE" then
if v then
v.Enabled = true
v:Emit(20)
print("Emitting particles
from", v.Name)
end
end
end
clone.AssemblyLinearVelocity = Vector3.new(0,
math.random(50, 80), 0) +
clone.CFrame.RightVector * math.random(-
30, 30) +
clone.CFrame.LookVector * math.random(-
30, 30)
clone.AssemblyAngularVelocity =
Vector3.new(math.random(-8, 8), math.random(-8, 8), math.random(-8, 8))
clone.Parent = workspace
task.delay(duration - 1, function()
fadeOutTween:Play()
fadeOutTween.Completed:Connect(function()
clone:Destroy()
end)
end)
end
end
task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end
parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end
if parentModel:GetAttribute("Destroyable") then
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = false
p.Transparency = 1
p:SetAttribute("Destroyable", false)
task.delay(duration, function()
for _, p in pairs(parentModel:GetDescendants()) do
if p:IsA("BasePart") then
p.Anchored = true
p.CanCollide = true
p.Transparency = 0
p:SetAttribute("Destroyable", true)
end
end
parentModel:SetAttribute("IsBeingDestroyed", false)
end)
end
end
end
end
return module