There's this ragdoll script, where if my health goes down to 0 my character ragdolls to the ground and I respawn. For some reason, after I respawn my ragdoll body is still there on the floor, so now there's 2 of me. How do I fix this?
GIF: https://gyazo.com/3cc968005c3de098e1870206f2cffe96
Script:
print("Ragdoll script activated")
Gibs = game.Workspace.Debris
ragdollstaytime = 5
ragdolltype = "Glue"
function getKillerOfHumanoidIfStillInGame(humanoid)
local tag = humanoid:findFirstChild("player")
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then
return killer
end
end
return nil
end
function OnDeath(Character)
local svch = Character
local hum = Character:findFirstChild("Humanoid")
local getkiller = getKillerOfHumanoidIfStillInGame(hum)
Character.Archivable = true
local chrclone = Character:clone()
Character.Archivable = true
local ch = chrclone:GetChildren()
local i
for i = 1,#ch do
if ch[i].Name == "THandle1" or ch[i].Name == "THandle2" or ch[i].ClassName == "Script" then
ch[i]:remove()
end
end
local function Scan(ch)
local e
for e = 1,#ch do
Scan(ch[e]:GetChildren())
if ch[e].ClassName == "Glue" or ch[e].ClassName == "Motor6D" then
ch[e]:remove()
end
end
end
Scan(chrclone:GetChildren())
local hum2 = chrclone:findFirstChild("Humanoid")
if hum2 ~= nil then
hum2.Name = ""
hum2.Sit = true
hum2.PlatformStand = true
hum2.MaxHealth = 0
hum2.Health = 0
end
local ch = Character:GetChildren()
local i
for i = 1,#ch do
if ch[i].Name == "THandle1" or ch[i].Name == "THandle2" then
ch[i]:remove()
end
end
local ch = Character:GetChildren()
local i
for i = 1,#ch do
if ch[i].ClassName == "Part" or ch[i].ClassName == "Accessories" or ch[i].Name == "THandle1" or ch[i].Name == "THandle2" then
ch[i]:remove()
end
end
Character = chrclone
Character.Name="" --This will be the corpse's name when player is ragdolled, for example: The player died, his corpse will be named "Dead body"
Character = chrclone
local Torso = Character.Torso
local movevector = Vector3.new()
if Torso then
local hrp = Character:FindFirstChild("Humanoidtorso")
if hrp then
local Neck2 = Instance.new("Glue")
Neck2.Name = "neck"
Neck2.Part0 = Torso
Neck2.Part1 = hrp
Neck2.Parent = hrp
end
local Head = Character:FindFirstChild("Head")
if Head then
local Neck = Instance.new("Weld") --Change ("Weld") to ("Rotate") if you want the player's head to rotate in the ragdoll.
Neck.Name = "Neck"
Neck.Part0 = Torso
Neck.Part1 = Head
Neck.C0 = CFrame.new(0, 1.5, 0)
Neck.C1 = CFrame.new()
Neck.Parent = Torso
local nsc = script.CamAttach:clone()
nsc.CamPart.Value = hum2.Parent.Head
nsc.Disabled = false
nsc.Parent = svch
end
local Limb = Character:FindFirstChild("Right Arm")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(1.5, 0, 0)
local Joint = Instance.new(ragdolltype)
Joint.Name = "RightShoulder"
Joint.Part0 = Torso
Joint.Part1 = Limb
Joint.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.C1 = CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, 0, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, -0.5, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Left Arm")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(-1.5, 0, 0)
local Joint = Instance.new(ragdolltype)
Joint.Name = "LeftShoulder"
Joint.Part0 = Torso
Joint.Part1 = Limb
Joint.C0 = CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.C1 = CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, 0, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Right Leg")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(1.5, -1, 0)
local Joint = Instance.new(ragdolltype)
Joint.Name = "RightHip"
Joint.Part0 = Torso
Joint.Part1 = Limb
Joint.C0 = CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.C1 = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, 0, 0)
W.Parent = Limb
end
local Limb = Character:FindFirstChild("Left Leg")
if Limb then
Limb.CFrame = Torso.CFrame * CFrame.new(-0.5, -2, 0)
local Joint = Instance.new(ragdolltype)
Joint.Name = "LeftHip"
Joint.Part0 = Torso
Joint.Part1 = Limb
Joint.C0 = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.C1 = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
Joint.Parent = Torso
local B = Instance.new("Part")
B.TopSurface = 0
B.BottomSurface = 0
B.formFactor = "Symmetric"
B.Size = Vector3.new(1, 1, 1)
B.Transparency = 1
B.CFrame = Limb.CFrame * CFrame.new(0, -0.6, 0)
B.Parent = Character
local W = Instance.new("Weld")
W.Part0 = Limb
W.Part1 = B
W.C0 = CFrame.new(0, 0, 0)
W.Parent = Limb
end
--[
local Bar = Instance.new("Part")
Bar.TopSurface = 0
Bar.BottomSurface = 0
Bar.formFactor = "Symmetric"
Bar.Size = Vector3.new(1, 1, 1)
Bar.Transparency = 1
Bar.CFrame = Head.CFrame * CFrame.new(0, 0.5, 0)
Bar.Parent = Character
local Weld = Instance.new("Weld")
Weld.Part0 = Torso
Weld.Part1 = Bar
Weld.C0 = CFrame.new(0, 0, 0)
Weld.Parent = Torso
--]]
end
Character.Parent = Gibs
game.Debris:AddItem(Character, 60) --Change 60 to whatever number, it's the ragdoll stay time.
end
function onRespawn(character)
wait()
local humm = character:findFirstChild("Humanoid")
if humm ~= nil then
print("Ragdoll connection attached to " .. character.Name)
local bounce = false
local conn = humm.Died:connect(function()
if bounce then return end
bounce = false
OnDeath(character)
end)
end
end
function onPlayerEntered(newPlayer)
if newPlayer.ClassName ~= "Player" then return end
newPlayer.CharacterAdded:connect(onRespawn)
local checkChar = newPlayer.Character
if checkChar ~= nil then
onRespawn(checkChar)
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
local p2 = game.Players:GetPlayers()
local i2
for i2 = 0.01,#p2 do
onPlayerEntered(p2[i2])
end
