Hi, I found a zombie from the marketplace and when it dies, it has a death effect and then lies there for quite a while before being destroyed. Is there any way I can make it so that the zombie gets destroyed a bit quicker rather than just lying on the floor for ages?
function death()
candmg = false
if npc:findFirstChild("Health") then
npc.Health:Remove()
end
if head:findFirstChild("footstep") then
head.footstep:Remove()
end
npchumanoid.Archivable = true
local zombiecorpse = npchumanoid.Parent:Clone()
zombiecorpse:findFirstChildOfClass("Humanoid").Health = 0
zombiecorpse:BreakJoints()
if game.Players:GetPlayerFromCharacter(npchumanoid.Parent) then
game.Players:GetPlayerFromCharacter(npchumanoid.Parent):LoadCharacter()
else
npchumanoid.Parent:destroy()
end
zombiecorpse.Parent = workspace
if zombiecorpse:FindFirstChildWhichIsA("Tool") then
zombiecorpse:FindFirstChildWhichIsA("Tool").Parent = workspace
end
game.Debris:AddItem(zombiecorpse, 3)
local Humanoid = zombiecorpse:findFirstChildOfClass("Humanoid")
local Torso = zombiecorpse.Torso
Humanoid.PlatformStand = true
for i,v in pairs(Humanoid.Parent.Torso:GetChildren()) do
if v.ClassName == 'Motor6D' or v.ClassName == 'Weld' then
v:destroy()
end
end
for i,v in pairs(zombiecorpse:GetChildren()) do
if v.ClassName == "Part" then
for q,w in pairs(v:GetChildren()) do
if w.ClassName == "BodyPosition" or w.ClassName == "BodyVelocity" then
w:destroy()
end
end
end
end
if zombiecorpse:findFirstChild("Head") then
local deathrandom = math.random(1,7)
local deathsound = Instance.new("Sound", zombiecorpse.Head)
deathsound.Volume = 0
if deathrandom == 1 then
deathsound.SoundId = "rbxassetid://131138845"
end
if deathrandom == 2 then
deathsound.SoundId = "rbxassetid://131138839"
end
if deathrandom == 3 then
deathsound.SoundId = "rbxassetid://131138850"
end
if deathrandom == 4 then
deathsound.SoundId = "rbxassetid://131138860"
end
if deathrandom == 5 then
deathsound.SoundId = "rbxassetid://131138854"
end
if deathrandom == 6 then
deathsound.SoundId = "rbxassetid://131138848"
end
if deathrandom == 7 then
deathsound.SoundId = "rbxassetid://461063380"
end
end
local function makeconnections(limb, attachementone, attachmenttwo, twistlower, twistupper, upperangle)
local connection = Instance.new('BallSocketConstraint', limb)
connection.LimitsEnabled = true
connection.Attachment0 = attachementone
connection.Attachment1 = attachmenttwo
connection.TwistLimitsEnabled = true
connection.TwistLowerAngle = twistlower
connection.TwistUpperAngle = twistupper
connection.UpperAngle = 70
end
local function makehingeconnections(limb, attachementone, attachmenttwo, twistlower, twistupper, upperangle)
local connection = Instance.new('HingeConstraint', limb)
connection.Attachment0 = attachementone
connection.Attachment1 = attachmenttwo
connection.LimitsEnabled = true
connection.LowerAngle = twistlower
connection.UpperAngle = twistupper
end
Humanoid.Parent['Right Arm'].RightShoulderAttachment.Position = Vector3.new(0, 0.5, 0)
Torso.RightCollarAttachment.Position = Vector3.new(1.5, 0.5, 0)
Humanoid.Parent['Left Arm'].LeftShoulderAttachment.Position = Vector3.new(0, 0.5, 0)
Torso.LeftCollarAttachment.Position = Vector3.new(-1.5, 0.5, 0)
local RightLegAttachment = Instance.new("Attachment", Humanoid.Parent["Right Leg"])
RightLegAttachment.Position = Vector3.new(0, 1, 0)
local TorsoRightLegAttachment = Instance.new("Attachment", Torso)
TorsoRightLegAttachment.Position = Vector3.new(0.5, -1, 0)
--
local LeftLegAttachment = Instance.new("Attachment", Humanoid.Parent["Left Leg"])
LeftLegAttachment.Position = Vector3.new(0, 1, 0)
local TorsoLeftLegAttachment = Instance.new("Attachment", Torso)
TorsoLeftLegAttachment.Position = Vector3.new(-0.5, -1, 0)
--
if Humanoid.Parent:findFirstChild("Head") then
local HeadAttachment = Instance.new("Attachment", Humanoid.Parent.Head)
HeadAttachment.Position = Vector3.new(0, -0.5, 0)
makehingeconnections(Humanoid.Parent.Head, HeadAttachment, Torso.NeckAttachment, -20, 20, 70)
end
makeconnections(Humanoid.Parent['Right Arm'], Humanoid.Parent['Right Arm'].RightShoulderAttachment, Torso.RightCollarAttachment, -80, 80)
makeconnections(Humanoid.Parent['Left Arm'], Humanoid.Parent['Left Arm'].LeftShoulderAttachment, Torso.LeftCollarAttachment, -80, 80)
makeconnections(Humanoid.Parent['Right Leg'], RightLegAttachment, TorsoRightLegAttachment, -80, 80, 70)
makeconnections(Humanoid.Parent['Left Leg'], LeftLegAttachment, TorsoLeftLegAttachment, -80, 80, 70)
if Humanoid.Parent:findFirstChild("Right Arm") then
local limbcollider = Instance.new("Part", Humanoid.Parent["Right Arm"])
limbcollider.Size = Vector3.new(1,1.3,1)
limbcollider.Shape = "Cylinder"
limbcollider.Transparency = 1
local limbcolliderweld = Instance.new("Weld", limbcollider)
limbcolliderweld.Part0 = Humanoid.Parent["Right Arm"]
limbcolliderweld.Part1 = limbcollider
limbcolliderweld.C0 = CFrame.fromEulerAnglesXYZ(0,0,math.pi/2) * CFrame.new(-0.4,0,0)
for i,v in pairs(zombiecorpse["Right Arm"]:GetChildren()) do
if v.ClassName == 'Motor6D' or v.ClassName == 'Weld' then
v:destroy()
end
end
end
--
if Humanoid.Parent:findFirstChild("Left Arm") then
local limbcollider = Instance.new("Part", Humanoid.Parent["Left Arm"])
limbcollider.Size = Vector3.new(1,1.3,1)
limbcollider.Shape = "Cylinder"
limbcollider.Transparency = 1
local limbcolliderweld = Instance.new("Weld", limbcollider)
limbcolliderweld.Part0 = Humanoid.Parent["Left Arm"]
limbcolliderweld.Part1 = limbcollider
limbcolliderweld.C0 = CFrame.fromEulerAnglesXYZ(0,0,math.pi/2) * CFrame.new(-0.4,0,0)
end
--
if Humanoid.Parent:findFirstChild("Left Leg") then
local limbcollider = Instance.new("Part", Humanoid.Parent["Left Leg"])
limbcollider.Size = Vector3.new(1,1.3,1)
limbcollider.Shape = "Cylinder"
limbcollider.Transparency = 1
local limbcolliderweld = Instance.new("Weld", limbcollider)
limbcolliderweld.Part0 = Humanoid.Parent["Left Leg"]
limbcolliderweld.Part1 = limbcollider
limbcolliderweld.C0 = CFrame.fromEulerAnglesXYZ(0,0,math.pi/2) * CFrame.new(-0.4,0,0)
end
--
if Humanoid.Parent:findFirstChild("Right Leg") then
local limbcollider = Instance.new("Part", Humanoid.Parent["Right Leg"])
limbcollider.Size = Vector3.new(1,1.3,1)
limbcollider.Shape = "Cylinder"
limbcollider.Transparency = 1
local limbcolliderweld = Instance.new("Weld", limbcollider)
limbcolliderweld.Part0 = Humanoid.Parent["Right Leg"]
limbcolliderweld.Part1 = limbcollider
limbcolliderweld.C0 = CFrame.fromEulerAnglesXYZ(0,0,math.pi/2) * CFrame.new(-0.4,0,0)
end
Humanoid.Health = 0
local ragdoll = zombiecorpse
if ragdoll:findFirstChild("HumanoidRootPart") then
ragdoll.HumanoidRootPart.CanCollide = false
ragdoll.HumanoidRootPart:destroy()
end
wait(0.5)
for i,v in pairs(ragdoll:GetChildren()) do
if v.ClassName == 'Script' then
v.Disabled = true
end
end
end
npchumanoid.Died:connect(death)
while step:wait() do --check animations and other things
sine = sine + 1
if not walking then
footstep.Volume = 0
if neck then
neck.C0 = neck.C0:lerp(CFrame.new(0,1.2,0) * CFrame.Angles(math.sin(sine/30)/10,0,0) * CFrame.new(0,0.25,0),0.1)
end
righthip.C0 = righthip.C0:lerp(CFrame.new(0.5,-1-math.cos(sine/30)/15,0) * CFrame.Angles(math.rad(10+(2*math.sin(-sine/30))),0,-math.sin(sine/60)/10) * CFrame.new(0,-1,0),0.1)
lefthip.C0 = lefthip.C0:lerp(CFrame.new(-0.5,-1-math.cos(sine/30)/15,0) * CFrame.Angles(math.rad(10+(2*math.sin(-sine/30))),0,-math.sin(sine/60)/10) * CFrame.new(0,-1,0),0.1)
root.C0 = root.C0:lerp(CFrame.new(0,math.cos(sine/30)/15,0) * CFrame.Angles(math.rad(-10+(2*math.sin(sine/30))),0,math.sin(sine/60)/15),0.1)
rightshoulder.C0 = rightshoulder.C0:lerp(CFrame.new(1.5,0.5,0) * CFrame.Angles(math.rad(20)+math.rad(5*math.sin(sine/30)),0,math.rad(5*math.cos(sine/30)/2)) * CFrame.new(0,-0.5,0),0.1)
leftshoulder.C0 = leftshoulder.C0:lerp(CFrame.new(-1.5,0.5,0) * CFrame.Angles(math.rad(20)-math.rad(5*math.sin(sine/30)),0,-math.rad(5*math.cos(sine/30)/2)) * CFrame.new(0,-0.5,0),0.1)
end
if walking then --this is the walking animation
footstep.Volume = 0.5
leftshoulder.C0 = leftshoulder.C0:lerp(CFrame.new(-1.5,0.5,0) * CFrame.Angles(math.rad(100-math.cos(sine/5)*10),0,math.rad(math.sin(sine/10)*10)) * CFrame.new(0,-0.5,0),0.1)
rightshoulder.C0 = rightshoulder.C0:lerp(CFrame.new(1.5,0.5,0) * CFrame.Angles(math.rad(100-math.cos(sine/5)*10),0,math.rad(math.sin(sine/10)*10)) * CFrame.new(0,-0.5,0),0.1)
if neck then
neck.C0 = neck.C0:lerp(CFrame.new(0,1.2,0) * CFrame.Angles(math.rad(10+math.cos(sine/5)*6),0,0) * CFrame.new(0,0.25,0),0.1)
end
root.C0 = root.C0:lerp(CFrame.new(0,math.sin(sine/5)/9,0) * CFrame.Angles(math.rad(-15),0,math.cos(sine/10)/6),0.1)
righthip.C0 = righthip.C0:lerp(CFrame.new(0.5,-1+math.cos(sine/10)/3,-math.cos(sine/10)/3) * CFrame.Angles(math.sin(sine/10),0,0) * CFrame.new(0,-1,0),0.1)
lefthip.C0 = lefthip.C0:lerp(CFrame.new(-0.5,-1-math.cos(sine/10)/3,math.cos(sine/10)/3) * CFrame.Angles(-math.sin(sine/10),0,0) * CFrame.new(0,-1,0),0.1)
end
end
Thanks, sorry that its a lot of code, its just the whole of the death function