R6 Ragdoll with corpse

Hi ^^

I’m trying create a ragdoll on death script that keeps the corpse even if the player respawns.

I currently have a working ragdoll script, but I can’t figure out how to keep the corpse if the player respawns.

Here is my code:

local humanoid = script.Parent:WaitForChild("Humanoid")

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	for index,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end)

Also I’m trying to store the corpse in a debris folder in workspace.

All help is very appreciated :pray:

you can clone the character as long as you enable Archivable

local humanoid = script.Parent:WaitForChild("Humanoid")

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	for index,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
	
	task.wait(game:GetService("Players").RespawnTime)

	script.Parent.Archivable = true

	local Ragdoll = script.Parent:Clone()

	if Ragdoll:FindFirstChild("Health") then
		Ragdoll.Health:Destroy()
	end

	Ragdoll.Parent = workspace -- replace this with your debris folder
	
	Ragdoll.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	Ragdoll.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
end)
1 Like

Thank you so much for your help!

That works for the most part but it has a lot of issues.
For example the ragdoll only clones every few tries. And when it does clone, after a few seconds the humanoid stands up causing the ragdoll to do a funny dance looking thing.
I think this is due to the way the script was structured, causing it to be unreliable.

Is there a better way to clone the ragdoll instead of waiting the respawn time?

idk the problem behind it not cloning sometimes cause i cant reproduce the bug but for the ragdoll getting up before

anyway for the ragdolls standing up i forgot to add it before but before using ChangeState add this (and also make sure to use a server script):

for _, Limb in pairs(Ragdoll:GetDescendants()) do
	if Limb:IsA("BasePart") then
		Limb:SetNetworkOwner(nil)
	end
end