What do you want to achieve?
I want to clone a player’s character into workspace when they die, keeping it there (basically a corpse).
What is the issue?
The corpse rises back to life.
What solutions have you tried so far?
I’ve tried removing the character’s Humanoid which stops the corpse from “rising back to life”, but it removes their clothes which I don’t want. I’ve also tried setting the corpse’s humanoid state to Dead, but that didn’t work either.
Here is the code I’m currently using:
local corpsesFolder = workspace:WaitForChild("Corpses")
...
player.CharacterRemoving:Connect(function(character)
local corpse = character:Clone()
for _, v in pairs(corpse:GetDescendants()) do
if v:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(v, "Default")
elseif v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
corpse.Name = character.Name .. "Corpse"
corpse.Parent = corpsesFolder
end)
I’ve tried to find a post about this topic, but none of them I’ve found are fully resolved. Appreciate any help!
local chr= script.Parent
local hmn= chr:waitForChild'Humanoid'
hmn.BreakJointsOnDeath= false
hmn.Died:connect(function()
local clone= chr:clone()
clone.Parent= workspace:WaitForChild("Corpses")
end)
If you want the Corpses to not move, fix it like this:
local chr= script.Parent
chr.Archivable= true
local hmn= chr:waitForChild'Humanoid'
hmn.BreakJointsOnDeath= false
hmn.Died:connect(function()
local clone= chr:clone()
for k, child in pairs(clone:getChildren()) do
wait()
if child:isA'Script' then child:Destroy()
elseif child:isA'BasePart' then child.Anchored= true end
end
clone.Parent= workspace:WaitForChild("Corpses")
end)
I forgot to mention that I’m using a ragdoll module. I have the player’s character ragdoll when they die, and I want that to stay (so anchoring is not an option). Here’s more of the script:
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Archivable = true
local Humanoid = character:WaitForChild("Humanoid")
Humanoid.BreakJointsOnDeath = false
Humanoid.RequiresNeck = false
Humanoid.AutoJumpEnabled = false
end)
player.CharacterRemoving:Connect(function(character)
local corpse = character:Clone()
for _,v in pairs(corpse:GetDescendants()) do
if v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
-- Added corpse.Humanoid:Destroy() here
-- Which makes it work, but it removes their clothes
corpse.Name = character.Name .. "Corpse"
corpse.Parent = corpsesFolder
end)
end)
I ran into the same issue a few months back and came up with the following improvized solution, which I’m pretty sure isn’t the most ideal, but it’s quick enough. Apparently cloning a humanoid will make Roblox think that it’s alive despite its current state. I fixed it by putting the cloned humanoid’s health up to 100, giving it a .1 wait time and killing it again. It didn’t get back up. Try it out!
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Archivable = true
local Humanoid = character:WaitForChild("Humanoid")
Humanoid.BreakJointsOnDeath = false
Humanoid.RequiresNeck = false
Humanoid.AutoJumpEnabled = false
end)
player.CharacterRemoving:Connect(function(character)
if character.Humanoid.Health == 0 then
local corpse = character:Clone()
corpse.Parent = corpsesFolder
for _,v in pairs(corpse:GetDescendants()) do
if v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
corpse.Humanoid.Health = 100
corpse.Name = character.Name .. "Corpse"
wait(.1)
corpse.Humanoid:TakeDamage(100)
end
end)
end)
Thank you, this ended up working! Also learned that instead of destroying the Motor6D joints when the player ragdolls, I needed to disable them because Roblox would recreate them when the character was cloned. Here’s what I ended up with:
...
player.CharacterRemoving:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
if Humanoid.Health == 0 then
local corpse = character:Clone()
for _,v in pairs(corpse:GetDescendants()) do
if v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
corpse.Name = character.Name .. "Corpse"
corpse.Parent = corpsesFolder
corpse.Humanoid.Health = 100
wait(.1)
corpse.Humanoid.Health = 0
end
end)
Edit: If anyone has a better solution that isn’t as “Hacky” please let me know
Bringing this topic back because sometimes the corpses are rising back up still. There has to be a better solution rather than setting their health to 100 then back to 0. Has anyone else had this problem?
Try making a script and putting it in StarterCharacterScripts with this
local debris = game:GetService('Debris')
local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(script.Parent)
local humanoid = character:WaitForChild('Humanoid')
local bodyDisposeTime = 30
humanoid.Died:Connect(function()
if player ~= nil and humanoid ~= nil then
character.Archivable = true
script.Parent = game.ServerScriptService
local cloneChar = character:Clone()
cloneChar.Name = player.Name.."'s Deadbody"
if workspace:FindFirstChild(cloneChar.Name) then
workspace:FindFirstChild(cloneChar.Name):Destroy()
end
wait(0.1)
cloneChar.Parent = workspace
local rootPart = cloneChar.HumanoidRootPart or cloneChar.Torso
local clonedHumanoid = cloneChar:FindFirstChildOfClass("Humanoid")
cloneChar:MoveTo(rootPart.Position)
rootPart.Orientation = Vector3.new(90,0,0)
clonedHumanoid.PlatformStand = true
clonedHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
clonedHumanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
for i, v in pairs(cloneChar:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = false
v.CanCollide = false
end
if v:IsA("Script") or v:IsA("LocalScript") then
v:Destroy()
end
end
if cloneChar:FindFirstChild("ForceField") then
cloneChar.ForceField:Destroy()
end
character.Parent = game:GetService("ServerStorage")
debris:AddItem(cloneChar,bodyDisposeTime)
debris:AddItem(script,bodyDisposeTime)
wait(1)
if rootPart.Orientation ~= Vector3.new(90,0,0) then
rootPart.Orientation = Vector3.new(90,0,0)
end
end
end)