How to make corpse when player dies

Hello !
I’m trying to make, when the player die, like copy his player model, and then ragdoll it, I’m using this script :

--Made by ParionFire

local function ConnectLimbs(char)
	for i, limb in pairs(char:GetChildren()) do
		if limb:IsA("BasePart") then
			local atch0, atch1, atch2, atch3, atch4, atch5
			
			if limb.Name == "Head" then
				atch0 = char.Head.NeckRigAttachment
				atch1 = char.UpperTorso.NeckRigAttachment
			elseif limb.Name == "UpperTorso" then
				atch0 = char.UpperTorso.WaistRigAttachment
				atch1 = char.LowerTorso.WaistRigAttachment
				
				atch2 = char.UpperTorso.LeftShoulderRigAttachment
				atch3 = char.LeftUpperArm.LeftShoulderRigAttachment
				
				atch4 = char.UpperTorso.RightShoulderRigAttachment
				atch5 = char.RightUpperArm.RightShoulderRigAttachment
			elseif limb.Name == "LowerTorso" then
				atch0 = char.LowerTorso.LeftHipRigAttachment
				atch1 = char.LeftUpperLeg.LeftHipRigAttachment
				
				atch2 = char.LowerTorso.RightHipRigAttachment
				atch3 = char.RightUpperLeg.RightHipRigAttachment
			elseif limb.Name == "LeftUpperLeg" then
				atch0 = char.LeftUpperLeg.LeftKneeRigAttachment
				atch1 = char.LeftLowerLeg.LeftKneeRigAttachment
			elseif limb.Name == "RightUpperLeg" then
				atch0 = char.RightUpperLeg.RightKneeRigAttachment
				atch1 = char.RightLowerLeg.RightKneeRigAttachment
			elseif limb.Name == "LeftLowerLeg" then
				atch0 = char.LeftLowerLeg.LeftAnkleRigAttachment
				atch1 = char.LeftFoot.LeftAnkleRigAttachment
			elseif limb.Name == "RightLowerLeg" then
				atch0 = char.RightLowerLeg.RightAnkleRigAttachment
				atch1 = char.RightFoot.RightAnkleRigAttachment
			elseif limb.Name == "LeftUpperArm" then
				atch0 = char.LeftUpperArm.LeftElbowRigAttachment
				atch1 = char.LeftLowerArm.LeftElbowRigAttachment
			elseif limb.Name == "RightUpperArm" then
				atch0 = char.RightUpperArm.RightElbowRigAttachment
				atch1 = char.RightLowerArm.RightElbowRigAttachment
			elseif limb.Name == "LeftLowerArm" then
				atch0 = char.LeftLowerArm.LeftWristRigAttachment
				atch1 = char.LeftHand.LeftWristRigAttachment
			elseif limb.Name == "RightLowerArm" then
				atch0 = char.RightLowerArm.RightWristRigAttachment
				atch1 = char.RightHand.RightWristRigAttachment
			end
			
			if atch0 and atch1 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch0
				ballInSocket.Attachment1 = atch1
			end
			
			if atch2 and atch3 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch2
				ballInSocket.Attachment1 = atch3
			end
			
			if atch4 and atch5 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch4
				ballInSocket.Attachment1 = atch5
			end
			
		elseif limb:IsA("Accessory") then
			local h = limb:FindFirstChild("Handle")
			if h then
				local part0 = char.Head
				local atch = h:FindFirstChildOfClass("Attachment")
				
				if atch.Name == "HatAttachment" or atch.Name == "FaceFrontAttachment" then
					part0 = char.Head
				end
				
				local ap = Instance.new("AlignPosition", part0)
				if part0 == char.Head then
					ap.Attachment1 = char.Head:FindFirstChild(atch.Name)
					ap.Attachment0 = atch
					ap.RigidityEnabled = true
					ap.Responsiveness = 200
				end
				
				local ao = Instance.new("AlignOrientation", part0)
				if part0 == char.Head then
					ao.Attachment1 = char.Head:FindFirstChild(atch.Name)
					ao.Attachment0 = atch
					ao.RigidityEnabled = true
					ao.Responsiveness = 200
				end
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			ConnectLimbs(char)
		end)
	end)
end)

But I honnestly don’t know how to modify it to make the ragdoll stay for like 5 minutes ^^’

3 Likes

Just after the

ConnectLimbs(char)

do

wait(5)
char:Destroy()

That simple lol.
Let me know if u have any problems. :grinning_face_with_smiling_eyes:

1 Like

That easy? Lmao i thought that would be more difficult :,)

also if you are doing that u might wanna change the respawn time. Its located in players.
image
image

No need, I’m doing something else.
When player die, he’s redirected to spectator team where he can spec alive player.
Corpse just says that a threat is near

It doesn’t seems to work, when the player respawn they directly remove the corpse

1 Like

You could do something like this, I don’t think you need to clone the player. If you do you can simply clone the players Character.

local function CreateRagdoll(character)
   local character = character:Clone(); character.Parent = workspace
   for _, Joint in pairs(character:GetDescendants()) do
      if Joint:IsA("Motor6D") then
         local Socket = Instance.new("BallSocketConstraint")
         local a1, 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.LimitesEnabled = true
         Socket.TwistLimitsEnabled = true
      end
   end
end

This is for the Ragdoll, the clone is optional, remove it if you don’t need it. Link this to Humanoid.Died and make sure to change the respawn time so you don’t get respawned. Hope this helps.

Edit: You may need to add this:

game:GetService("Players").PlayerAdded:Connect(function(plr)
   plr.CharacterAdded:Connect(function(char)
      local Humanoid = char:WaitForChild("Humanoid")
      Humanoid.BreakJointsOnDeath = false -- This line
      Humanoid.Died:Connect(function()
          CreateRagdoll(char)
      end)
   end
end

Should I paste it in my current or replace it?

You should replace it, since your current one is quite long and hard to read.

1 Like

It doesn’t fill what I’m searching, with this script, avatar just stand up and respawn aftar 10 seconds

What’s happening here is the characters state called Getting Up is firing, I think what you can do is change the state to physics I believe Humanoid:ChangeState(Enum.HumanoidStateType.Physics).

Oh wait I think I found a post that is trying to answer my question :

1 Like

I got this script so :

local function ConnectLimbs(char)
	for i, limb in pairs(char:GetChildren()) do
		if limb:IsA("BasePart") then
			local atch0, atch1, atch2, atch3, atch4, atch5

			if limb.Name == "Head" then
				atch0 = char.Head.NeckRigAttachment
				atch1 = char.UpperTorso.NeckRigAttachment
			elseif limb.Name == "UpperTorso" then
				atch0 = char.UpperTorso.WaistRigAttachment
				atch1 = char.LowerTorso.WaistRigAttachment

				atch2 = char.UpperTorso.LeftShoulderRigAttachment
				atch3 = char.LeftUpperArm.LeftShoulderRigAttachment

				atch4 = char.UpperTorso.RightShoulderRigAttachment
				atch5 = char.RightUpperArm.RightShoulderRigAttachment
			elseif limb.Name == "LowerTorso" then
				atch0 = char.LowerTorso.LeftHipRigAttachment
				atch1 = char.LeftUpperLeg.LeftHipRigAttachment

				atch2 = char.LowerTorso.RightHipRigAttachment
				atch3 = char.RightUpperLeg.RightHipRigAttachment
			elseif limb.Name == "LeftUpperLeg" then
				atch0 = char.LeftUpperLeg.LeftKneeRigAttachment
				atch1 = char.LeftLowerLeg.LeftKneeRigAttachment
			elseif limb.Name == "RightUpperLeg" then
				atch0 = char.RightUpperLeg.RightKneeRigAttachment
				atch1 = char.RightLowerLeg.RightKneeRigAttachment
			elseif limb.Name == "LeftLowerLeg" then
				atch0 = char.LeftLowerLeg.LeftAnkleRigAttachment
				atch1 = char.LeftFoot.LeftAnkleRigAttachment
			elseif limb.Name == "RightLowerLeg" then
				atch0 = char.RightLowerLeg.RightAnkleRigAttachment
				atch1 = char.RightFoot.RightAnkleRigAttachment
			elseif limb.Name == "LeftUpperArm" then
				atch0 = char.LeftUpperArm.LeftElbowRigAttachment
				atch1 = char.LeftLowerArm.LeftElbowRigAttachment
			elseif limb.Name == "RightUpperArm" then
				atch0 = char.RightUpperArm.RightElbowRigAttachment
				atch1 = char.RightLowerArm.RightElbowRigAttachment
			elseif limb.Name == "LeftLowerArm" then
				atch0 = char.LeftLowerArm.LeftWristRigAttachment
				atch1 = char.LeftHand.LeftWristRigAttachment
			elseif limb.Name == "RightLowerArm" then
				atch0 = char.RightLowerArm.RightWristRigAttachment
				atch1 = char.RightHand.RightWristRigAttachment
			end

			if atch0 and atch1 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch0
				ballInSocket.Attachment1 = atch1
			end

			if atch2 and atch3 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch2
				ballInSocket.Attachment1 = atch3
			end

			if atch4 and atch5 then
				local ballInSocket = Instance.new("BallSocketConstraint", limb)
				ballInSocket.Attachment0 = atch4
				ballInSocket.Attachment1 = atch5
			end

		elseif limb:IsA("Accessory") then
			local h = limb:FindFirstChild("Handle")
			if h then
				local part0 = char.Head
				local atch = h:FindFirstChildOfClass("Attachment")

				if atch.Name == "HatAttachment" or atch.Name == "FaceFrontAttachment" then
					part0 = char.Head
				end

				local ap = Instance.new("AlignPosition", part0)
				if part0 == char.Head then
					ap.Attachment1 = char.Head:FindFirstChild(atch.Name)
					ap.Attachment0 = atch
					ap.RigidityEnabled = true
					ap.Responsiveness = 200
				end

				local ao = Instance.new("AlignOrientation", part0)
				if part0 == char.Head then
					ao.Attachment1 = char.Head:FindFirstChild(atch.Name)
					ao.Attachment0 = atch
					ao.RigidityEnabled = true
					ao.Responsiveness = 200
				end
			end
		end
	end
end


game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Died:Connect(function()
			ConnectLimbs(Character)
			local test = (Character:GetChildren())

			local testing = Instance.new("Model",workspace)
			for i = 1, #test do
				local child = test[i]
				child:Clone()
				child.Parent = testing
			end
		end)
	end)

end)

But for some reason it doesn’t copy the player model

At the start of the function put char = char:Clone() char.Parent = workspace this should clone the character model.

Oh nice it fixed the problem ^^
My corpse is just so weird :,)
How can I modify to make the corpse despawn after like 5 minutes?

You could look into DebrisService, this will help your current problem or you could just add a wait(300) maybe since, even if the player leaves it the cloned model would still be there.

I tried to use this :
game:GetService("Debris"):AddItem(Character, 300)
But it didn’t work

Can I see the script where you implemented it?

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		
		Character:WaitForChild("Humanoid").Died:Connect(function()
			ConnectLimbs(Character)
			game:GetService("Debris"):AddItem(Character, 300)
			local test = (Character:GetChildren())
			local testing = Instance.new("Model",workspace)
			for i = 1, #test do
				local child = test[i]
				child:Clone().Parent = testing
			end
		end)
	end)
end)

At the end of the function

You should be adding the cloned model to the character, so add that line into the function after you cloned the model.