How to use the debris service for making corpses after a player has died (with ragdoll)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A system where if a player dies in a R6 rig, his body gets ragdolled and remains on the floor for a minute or so. i have a r15 version, but the body stays forever and the ragdolled body is visible only for the server.

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    ive gotten support from some creators but the problem remained the same…
    script goes to serverscriptservice.

local players = game:GetService("Players")

local function makeRagDoll(doll)
	for index, joint in pairs (doll: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

local function makeDup(char)
	
	char.Archivable = true
	local dChar = char:Clone()
	char.Archivable = false
	dChar.Parent = workspace
	
	for i, v in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = true
			v.Transparency = 1
		end
	end
	
	local healthScript = dChar:FindFirstChild("Health")
	if healthScript then
		healthScript.Enabled = false
	end
	
	if dChar then
		makeRagDoll(dChar)
	else
		warn("No Character Duplicate!")
	end
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.Died:Connect(function()
			print("Player Has Died!", player.Name)
			makeDup(char)
		end)
	end)
end)

Thanks again for reading
(yes this is a repost cuz i haven’t gotten any help, if i cant do anything i might try researching again)

To clone the character’s rig, do this within the script.

  1. Make the character archivable, this will allow you to clone it.
  2. Ragdoll the new clone if its not already rag dolled.
  3. Make the character un-archivable once cloned.

After that just write this line of code.

game:GetService("Debris"):AddItem(ClonedCharacter, CORPSE_LIFETIME)

If you’d like to add some fading with Tween-Service you can do a function that runs on a thread (task.spawn or coroutine.wrap) and you can do the deletion your self without using the Debris-Service and without any yielding.

Thanks alot! this is definently giving me a step further into fixing these bugs, although the character is ragdolled when its dead, its the fact that once i touch it (on client) it stands up, but whenever i check on the server, its still ragdolled

1 Like

it works perfectly! thanks alot

1 Like

Awesome, I’m glad my idea has successfully worked for you - Happy Scripting!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.