Tutorial · Gameplay

How to make a ragdoll on death in Roblox Studio

When a Roblox character dies, its joints break and the body falls apart into loose pieces. A ragdoll keeps the body in one piece and lets it go limp: arms swing, knees fold and the character slumps to the floor. The trick is to swap each joint motor for a ball socket that bends but does not come apart. This guide builds one server Script that does that for every player, works on R15 and R6 avatars, and keeps the joints from bending in ways that look broken.

Updated 14 November 20268 min readIntermediateLuauWritten by

In short

Put a Script in ServerScriptService. For each new character, set humanoid.BreakJointsOnDeath = false. In humanoid.Died, loop over the character's Motor6D joints: put an Attachment at C0 in Part0 and one at C1 in Part1, join them with a BallSocketConstraint, then set the motor's Enabled to false. Skip the root joint.

  • BreakJointsOnDeath is true by default. Without turning it off, Roblox breaks the joints before your ragdoll code can run.
  • Motor6D joints have different names in R15 and R6, but every one has Part0, Part1, C0 and C1, so the same loop handles both.
  • Turn on the ball socket limits, or necks and shoulders spin all the way round.

Get the script

Ragdoll on death script for R15 and R6

One Script in ServerScriptService: when a player dies, every joint becomes a limited ball socket, so the body falls limp instead of breaking apart.

Script in ServerScriptService named RagdollOnDeath
-- Script in ServerScriptService named RagdollOnDeath.
-- When a player's character dies, its joints become ball sockets, so it falls limp in one piece.
local Players = game:GetService("Players")

local DEFAULT_ANGLE = 45 -- degrees a joint can bend when it has no entry below
local SERVER_OWNS_BODY = true -- the server simulates the body, so everyone sees the same fall

-- Limits per joint, found by a word in the motor's name (R15 "LeftShoulder", R6 "Left Shoulder")
type Limit = { angle: number, twist: number }
local JOINT_LIMITS: { [string]: Limit } = {
	neck = { angle = 30, twist = 40 },
	waist = { angle = 30, twist = 20 },
	shoulder = { angle = 90, twist = 45 },
	elbow = { angle = 60, twist = 5 },
	wrist = { angle = 30, twist = 10 },
	hip = { angle = 60, twist = 20 },
	knee = { angle = 60, twist = 5 },
	ankle = { angle = 30, twist = 10 },
}

local function getLimit(motorName: string): Limit
	local name = string.lower(motorName)
	for word, limit in JOINT_LIMITS do
		if string.find(name, word, 1, true) then
			return limit
		end
	end
	return { angle = DEFAULT_ANGLE, twist = DEFAULT_ANGLE }
end

local function ragdoll(character: Model, humanoid: Humanoid)
	local root = humanoid.RootPart
	for _, motor in character:GetDescendants() do
		if not motor:IsA("Motor6D") then
			continue
		end
		local part0, part1 = motor.Part0, motor.Part1
		-- Keep the root joint: it holds the invisible HumanoidRootPart to the body
		if not (part0 and part1) or part0 == root or part1 == root then
			continue
		end
		local a0 = Instance.new("Attachment")
		a0.Name = "RagdollAttachment0"
		a0.CFrame = motor.C0 -- the joint point, in Part0's space
		a0.Parent = part0
		local a1 = Instance.new("Attachment")
		a1.Name = "RagdollAttachment1"
		a1.CFrame = motor.C1 -- the same point, in Part1's space
		a1.Parent = part1

		local limit = getLimit(motor.Name)
		local socket = Instance.new("BallSocketConstraint")
		socket.Attachment0 = a0
		socket.Attachment1 = a1
		socket.LimitsEnabled = true
		socket.UpperAngle = limit.angle
		socket.TwistLimitsEnabled = true
		socket.TwistLowerAngle = -limit.twist
		socket.TwistUpperAngle = limit.twist
		socket.Parent = part1

		motor.Enabled = false -- the ball socket holds the parts now
	end

	-- Limbs collide with the floor so they do not sink into it; the root part does not
	for _, part in character:GetDescendants() do
		if part:IsA("BasePart") and part.Parent == character then
			part.CanCollide = part ~= root
		end
	end

	if SERVER_OWNS_BODY and root and not root.Anchored then
		-- pcall: ownership of anchored parts cannot be changed, so never let this stop the script
		pcall(function()
			root:SetNetworkOwner(nil)
		end)
	end
end

local function onCharacterAdded(character: Model)
	local humanoid = character:WaitForChild("Humanoid") :: Humanoid
	-- Without this, Roblox breaks every joint the moment the character dies
	humanoid.BreakJointsOnDeath = false
	humanoid.Died:Once(function()
		ragdoll(character, humanoid)
	end)
end

local function onPlayerAdded(player: Player)
	player.CharacterAdded:Connect(onCharacterAdded)
	if player.Character then
		task.spawn(onCharacterAdded, player.Character)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
	onPlayerAdded(player)
end

RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts

Where to put it

Explorer: one Script, nothing else to build
ServerScriptService
  RagdollOnDeath Script new

Settings you can change

DEFAULT_ANGLEIn the script
How far, in degrees, a joint without its own entry in JOINT_LIMITS can bend. Default: 45.
SERVER_OWNS_BODYIn the script
The server simulates the dead body, so every player sees it fall the same way. Default: true.

Players respawn 5 seconds after dying by default. To leave the body on the floor longer, raise RespawnTime on the Players service.

Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.

Prompt for RoCode

Add ragdoll on death to my game: one Script in ServerScriptService that sets BreakJointsOnDeath to false on every player character and, when the Humanoid dies, replaces every Motor6D except the root joint with a BallSocketConstraint between attachments at the motor C0 and C1, with angle and twist limits per joint (smaller for the neck), turns on collisions for the limbs, and works for R15 and R6.

On this page
  1. Get the script
  2. How it works
  3. 1. Script
  4. 2. Explained
  5. 3. NPCs
  6. 4. Test
  7. Common errors
  8. With RoCode
  9. Questions
  10. Sources

How a ragdoll works

A character's body parts are held together by Motor6D joints. A Motor6D holds two parts at a fixed offset and is what animations turn to move a limb. When the character dies, Roblox normally breaks those joints, and the parts fall separately.

A ragdoll swaps each Motor6D for a BallSocketConstraint. A ball socket joins two parts at one point and lets them rotate freely around it, like a shoulder. Turn on its limits and it only bends so far, so the body moves like a limp person instead of a bag of loose blocks.

Motor6D compared with BallSocketConstraint
Motor6DBallSocketConstraint
JoinsPart0 and Part1, using offsets C0 and C1Attachment0 and Attachment1
Moves byAnimationsPhysics only
BendsOnly as the animation saysFreely, up to UpperAngle and the twist limits

Step 1: The ragdoll Script

  1. Hover over ServerScriptService in the Explorer, click + and insert a Script. Name it RagdollOnDeath.
  2. Replace its contents with the code below.
  3. Press Play, then reset your character (Esc, then Reset Character).
Script in ServerScriptService named RagdollOnDeath
-- Script in ServerScriptService named RagdollOnDeath.
-- When a player's character dies, its joints become ball sockets, so it falls limp in one piece.
local Players = game:GetService("Players")

local DEFAULT_ANGLE = 45 -- degrees a joint can bend when it has no entry below
local SERVER_OWNS_BODY = true -- the server simulates the body, so everyone sees the same fall

-- Limits per joint, found by a word in the motor's name (R15 "LeftShoulder", R6 "Left Shoulder")
type Limit = { angle: number, twist: number }
local JOINT_LIMITS: { [string]: Limit } = {
	neck = { angle = 30, twist = 40 },
	waist = { angle = 30, twist = 20 },
	shoulder = { angle = 90, twist = 45 },
	elbow = { angle = 60, twist = 5 },
	wrist = { angle = 30, twist = 10 },
	hip = { angle = 60, twist = 20 },
	knee = { angle = 60, twist = 5 },
	ankle = { angle = 30, twist = 10 },
}

local function getLimit(motorName: string): Limit
	local name = string.lower(motorName)
	for word, limit in JOINT_LIMITS do
		if string.find(name, word, 1, true) then
			return limit
		end
	end
	return { angle = DEFAULT_ANGLE, twist = DEFAULT_ANGLE }
end

local function ragdoll(character: Model, humanoid: Humanoid)
	local root = humanoid.RootPart
	for _, motor in character:GetDescendants() do
		if not motor:IsA("Motor6D") then
			continue
		end
		local part0, part1 = motor.Part0, motor.Part1
		-- Keep the root joint: it holds the invisible HumanoidRootPart to the body
		if not (part0 and part1) or part0 == root or part1 == root then
			continue
		end
		local a0 = Instance.new("Attachment")
		a0.Name = "RagdollAttachment0"
		a0.CFrame = motor.C0 -- the joint point, in Part0's space
		a0.Parent = part0
		local a1 = Instance.new("Attachment")
		a1.Name = "RagdollAttachment1"
		a1.CFrame = motor.C1 -- the same point, in Part1's space
		a1.Parent = part1

		local limit = getLimit(motor.Name)
		local socket = Instance.new("BallSocketConstraint")
		socket.Attachment0 = a0
		socket.Attachment1 = a1
		socket.LimitsEnabled = true
		socket.UpperAngle = limit.angle
		socket.TwistLimitsEnabled = true
		socket.TwistLowerAngle = -limit.twist
		socket.TwistUpperAngle = limit.twist
		socket.Parent = part1

		motor.Enabled = false -- the ball socket holds the parts now
	end

	-- Limbs collide with the floor so they do not sink into it; the root part does not
	for _, part in character:GetDescendants() do
		if part:IsA("BasePart") and part.Parent == character then
			part.CanCollide = part ~= root
		end
	end

	if SERVER_OWNS_BODY and root and not root.Anchored then
		-- pcall: ownership of anchored parts cannot be changed, so never let this stop the script
		pcall(function()
			root:SetNetworkOwner(nil)
		end)
	end
end

local function onCharacterAdded(character: Model)
	local humanoid = character:WaitForChild("Humanoid") :: Humanoid
	-- Without this, Roblox breaks every joint the moment the character dies
	humanoid.BreakJointsOnDeath = false
	humanoid.Died:Once(function()
		ragdoll(character, humanoid)
	end)
end

local function onPlayerAdded(player: Player)
	player.CharacterAdded:Connect(onCharacterAdded)
	if player.Character then
		task.spawn(onCharacterAdded, player.Character)
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
	onPlayerAdded(player)
end

You can also untick CharacterBreakJointsOnDeath on StarterPlayer in the Properties window. It sets the starting value of BreakJointsOnDeath for every character, so the script's line becomes a backup.

Step 2: What each part does

Attachments at C0 and C1

A Motor6D stores where it joins the two parts as two offsets. C0 is the joint's position and rotation relative to Part0, and C1 is the same point relative to Part1. An Attachment's CFrame is also relative to the part it is in. So an Attachment in Part0 at C0 and one in Part1 at C1 sit on exactly the same spot in the world, which is the point the ball socket turns around.

Using the motor's own offsets means the script never needs to know where a shoulder or a knee is, which is why it works for R15, R6, scaled avatars and custom rigs alike.

The limits

With LimitsEnabled, UpperAngle is how far, in degrees, the second part can tilt away from the first. With TwistLimitsEnabled, TwistLowerAngle and TwistUpperAngle limit how far it can spin around the joint's own axis. A neck with 30 degrees of tilt and 40 of twist nods and turns but never spins all the way round. Elbows and knees get almost no twist, because real ones only fold.

getLimit finds the limit by a word in the motor's name, lower-cased. LeftShoulder and Left Shoulder both contain shoulder, so R15 and R6 share one table. A joint with no matching word, such as one in a custom rig, gets DEFAULT_ANGLE.

Why the root joint stays

Every character has an invisible HumanoidRootPart, joined to the body by a joint called Root on R15 and RootJoint on R6. The script leaves that joint alone, so the root part stays stuck to the lower body and moves with it. With collisions off on the root part, it does not prop the body up.

Collisions

While a character is alive, several of its body parts have collisions off. A ragdoll needs every limb to hit the floor, or the arms sink into it. The script turns CanCollide on for each body part directly inside the character. Parts inside accessories are not direct children, so hats and hair keep their own settings.

Who simulates the body

A living character is simulated by the player's own device. After death, SetNetworkOwner(nil) hands the body to the server, so every player sees the same fall. Roblox's network ownership page says the server always owns anchored parts and their ownership cannot be changed, so the call is wrapped in pcall in case something has anchored the body. Set SERVER_OWNS_BODY to false to leave it with the player.

Step 3: Ragdoll NPCs too

NPCs are Models with a Humanoid, the same as player characters. To ragdoll them, tag each NPC Ragdoll in the Properties window and add this to the bottom of the RagdollOnDeath Script. The code below repeats the ragdoll function in a short form so it can be checked on its own; in your game, call the ragdoll function from Step 1 instead of the stub.

Script in ServerScriptService named RagdollNpcs
-- Add to the bottom of RagdollOnDeath: NPCs tagged "Ragdoll" ragdoll on death too.
local CollectionService = game:GetService("CollectionService")

local function ragdoll(_character: Model, _humanoid: Humanoid)
	-- use the ragdoll function from Step 1
end

local function setUpNpc(npc: Instance)
	if not npc:IsA("Model") then
		return
	end
	local humanoid = npc:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		return
	end
	humanoid.BreakJointsOnDeath = false
	humanoid.Died:Once(function()
		ragdoll(npc, humanoid)
	end)
end

for _, npc in CollectionService:GetTagged("Ragdoll") do
	setUpNpc(npc)
end
CollectionService:GetInstanceAddedSignal("Ragdoll"):Connect(setUpNpc)

Roblox gives ownership of an unanchored NPC to a nearby player's device automatically, so the network owner line helps NPCs too. Clean up NPC bodies with task.delay(10, function() npc:Destroy() end) inside the Died handler, or they stay forever. The zombie survival guide spawns NPCs this script can ragdoll.

Step 4: Test it

  1. Press Play and walk to an open space.
  2. Press Esc and choose Reset Character. The body should fold to the floor in one piece instead of breaking apart.
  3. Die on a kill brick while running: the body keeps some of its speed and tumbles.
  4. Watch the neck and shoulders: they should bend but never spin round. If a joint looks wrong, lower its numbers in JOINT_LIMITS.
  5. If your game allows R6 avatars, test one too: the same script ragdolls it.
  6. To see the body from another player's view, start a local server with 2 players from the Test tab.

Common errors and fixes

If the body still breaks apart, check the Output window first: a red line names the script and the line.

The character still breaks into pieces

BreakJointsOnDeath was still true when the character died. Check the script is a Script in ServerScriptService, and untick CharacterBreakJointsOnDeath on StarterPlayer as a backup.

The body falls through the floor

The limbs are not colliding. Check the CanCollide loop runs, and that the floor itself has CanCollide on.

The body flings across the map

Two limbs are pushing against each other through a joint, or an accessory with collisions is wedged in the body. Lower the joint limits, or make sure accessory handles have CanCollide off.

The body stands up stiff

The motors are still enabled, or a script keeps the root part upright. Check that motor.Enabled = false runs and that no other script anchors the root part.

Neck and head spin around

Limits are off. Keep LimitsEnabled and TwistLimitsEnabled set to true.

Build it with RoCode

If you would rather not set this up by hand, RoCode can build it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer, so there is no code to paste.

You type

Make players and the zombies in my game ragdoll when they die instead of breaking apart, and keep the bodies on the floor for 8 seconds.

RoCode does
  • Can read your place first to find your NPCs and existing scripts, then adds the ragdoll Script
  • Writes the scripts with Create Script and is told to compile-check each one with Check Script
  • Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time

After a build, RoCode can run its test robot: it plays your game in Studio and reports PASS or FAIL. It checks only what it chose to test, so reset your character a few times yourself too. How RoCode connects to Studio.

Questions

How do you make a ragdoll on death in Roblox Studio?

Set BreakJointsOnDeath to false, then in Humanoid.Died replace each Motor6D with a BallSocketConstraint between Attachments at its C0 and C1. Step 1 has the full script.

Does this ragdoll work on R6 and R15?

Yes. Both rigs use Motor6D joints with Part0, Part1, C0 and C1. Only the names differ, and the script only uses names to pick joint limits.

Why does my ragdoll fall through the floor?

Some limbs have CanCollide off while alive. Turn it on for every body part when the ragdoll starts, except the HumanoidRootPart.

How do I make the body stay longer before respawning?

Raise RespawnTime on the Players service. It is 5 seconds by default.

Can I ragdoll a player without killing them?

It needs more than this script: Humanoid.RequiresNeck set to false so the character survives without its neck motor, and the state changes have to run on the player's device, which controls the character. Start from this death ragdoll and test that carefully.

Sources and further reading

How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

Try RoCode on your own place.

Free every day, no card required. Install the plugin, describe the feature, and review what lands in Studio.