Need help using ragdoll module to add ragdoll-on-death mechanic

I have a module script that applies a ragdoll effect to players, and it’s used in a weapon script. However, I also want to make it so players ragdoll on death instead of breaking apart like how characters normally die. Using this script, how do I do this?

(module script located in ServerScriptService. if i need to move it to ReplicatedStorage or something to make it easier it’s fine, just lmk)

local ragdoll = {}

function ragdoll.Start(character)
	if character.Humanoid.Health > 0 then
		if character.Ragdoll.Value then return end
		character.Ragdoll.Value = true
		for i, joint in pairs(character:GetDescendants()) do
			if joint:IsA("Motor6D") then
				local socket ="BallSocketConstraint")
				local a0 ="Attachment")
				local a1 ="Attachment")
				a0.Parent = joint.Part0
				a1.Parent = joint.Part1
				socket.Parent = joint.Parent
				socket.Attachment0 = a0
				socket.Attachment1 = a1
				a0.CFrame = joint.C0
				a1.CFrame = joint.C1
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true

				joint.Enabled = false

		character.Humanoid.WalkSpeed = 0
		character.Humanoid.JumpPower = 0

		character.Humanoid.PlatformStand = true

		character.Humanoid.AutoRotate = false

function ragdoll.Stop(character)
	local hrp = character:FindFirstChild("HumanoidRootPart")
	local hum = character:FindFirstChild("Humanoid")

	hum.PlatformStand = false

	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("BallSocketConstraint") then

		if joint:IsA("Motor6D") then
			joint.Enabled = true

	character.Ragdoll.Value = false


	hum.WalkSpeed = 24
	hum.JumpPower = 50

	hum.AutoRotate = true


return ragdoll

For one, you need to set Humanoid.BreakJointsOnDeath to false so that they do turn into lego pieces after they die. Then make a server script in StarterCharacterScripts that makes it so that when the Humanoid.Died signal goes off, you use ragdoll.Start() and send the argument as the player’s character.

1 Like