Basic R to Ragdoll Script

Edit 3: I realized the title was kind of clickbaity since the ragdoll itself didn’t look clean. After growing as a scripter I’ve realized that this is not really a reliable method to produce ragdolls and is more of a learning material. For serious purposes refer to this amazing ragdoll system. Enjoy my cringe post lol

TL;DR: I am very dumb and the kind souls @PineappleSmoothie12 and @Sir_Highness basically made a very good Temporary Ragdoll script for me.

Backstory on how this script was made: I always wanted to make a game where you ragdoll after jumping or free fall, kind of like a weird arcade game. But to do that, I needed a good Press key to Ragdoll script, and at the time there was only one available on Toolbox. I couldn’t guess heads from tails from that stuff as I am your average noob scripter. The other ragdoll scripts were made purely for ragdoll on death and thus they lacked polymorphism. But I found this one video on Youtube made by ShaunGamez (How to Make a Ragdoll Script in Roblox Studio! | ShaunGamez - YouTube) that had this simple bare bones ragdoll on death script:

game.Players.PlayerAdded:Connect(function(p)
 p.CharacterAdded:Connect(function(c)
  c.Humanoid.BreakJointsOnDeath = false
  c.Humanoid.Died:Connect(function()
   for _, v in pairs(c:GetDescendants()) do
    if v:IsA("Motor6D") then
     local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
     a0.CFrame = v.C0
     a1.CFrame = v.C1
     a0.Parent = v.Part0
     a1.Parent = v.Part1
     
     local b = Instance.new("BallSocketConstraint")
     b.Attachment0 = a0
     b.Attachment1 = a1
     b.Parent = v.Part0
     
     v:Destroy()
    end
   end
   c.HumanoidRootPart.CanCollide = false
  end)
 end)
end)

I messed around with this script which led me nowhere. v:Destroy() would kill the player everytime and I didn’t know how to unragdoll the player. But I couldn’t give up cuz this was the only ragdoll script I understood well. Then I found this post: Temporary Ragdoll? - #5 by dcampeon
I found Humanoid State types very easy to understand at first glance. I wanted to see what I could do with it. On the ChangeStateType documentation, there was a local double jump script which i modified to make a simple jump or freefall ragdoll which didn’t have any moving parts. It worked. Just needed to make it radgoll with moving parts. I knew how to make attachments and ballSocketConstraints but didn’t know about enabling or disabling motor6ds Thats where @PineappleSmoothie12 came in. Told me what I needed to do and what was wrong with my script. Took me a while to parse what they said cuz of the noob I am, but I finally managed to make a buggy ragdoll script which got the Job done.

local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.R then
		humanoid.BreakJointsOnDeath = false
		humanoid.RequiresNeck=false
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		for _, v in pairs(character:GetDescendants()) do
			if v:IsA("Motor6D") then
				local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
				a0.CFrame = v.C0
				a1.CFrame = v.C1
				a0.Parent = v.Part0
				a1.Parent = v.Part1
				local b = Instance.new("BallSocketConstraint")
				b.Attachment0 = a0
				b.Attachment1 = a1
				b.Parent = v.Part0
				v.Enabled = false
			end
		end
		wait(1)
		for _,v in pairs(character:GetDescendants()) do
			if v:IsA('Motor6D') then
				v.Enabled = true
			end
			if v.Name == 'BallSocketConstraint' then
				v:Destroy()
			end
			if v.Name == 'Attachment' then
				v:Destroy()
			end
		end
		wait(1)
		humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)	
	end
end)

It ragdolled when I pressed R and got back up again, although very weirdly. But I was pretty satisfied with what I got and called it a day. Then @Sir_Highness said that the script would be better if I did this and that and it didn’t have server script. which meant no one else could see you ragdolling. Then they basically revamped the script, made it more object oriented and made a server script. They fixed problems I would’ve never seen coming. The end result is the simplest and the most beautiful Press R to Ragdoll Script I have ever laid my eyes on! The code is so very intuitive to understand! I’m hoping any noob scripter like me would be able to reuse this code anywhere one could think of, instead of having to reinvent the wheel every time.

The thread where it happened: [SOLVED] Need Help with Temporary Ragdoll

Here’s a shoddy showcase: R to Ragdoll Showcase - Album on Imgur
Edit: Since you guys seem to like this, have even more shoddy showcases lol
R to Ragdoll Showcase 2 - Album on Imgur
R6: R6 R to Ragdoll Showcase - Album on Imgur

@Sir_Highness’s script:
The local character script:

local RagdollServerEvent = game.ReplicatedStorage:WaitForChild("RagdollServer")
local RagdollClientEvent = game.ReplicatedStorage:WaitForChild("RagdollClient")
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

UserInputService.InputBegan:Connect(function(inputObject, processed)
	if processed then return end --added this so you don't ragdoll when typing in chat
	if inputObject.KeyCode == Enum.KeyCode.R then
		humanoid.BreakJointsOnDeath = false
		humanoid.RequiresNeck=false
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
		RagdollServerEvent:FireServer(character)
		--wait(5)  this will be done on the server
	end	
end)

local function unragdoll()
	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	humanoid.BreakJointsOnDeath = true
	humanoid.RequiresNeck = true
end

RagdollClientEvent.OnClientEvent:Connect(unragdoll)

The Server script:

local RagdollServerEvent = Instance.new("RemoteEvent")
RagdollServerEvent.Name = "RagdollServer"
RagdollServerEvent.Parent = game.ReplicatedStorage
local RagdollClientEvent = Instance.new("RemoteEvent")
RagdollClientEvent.Name = "RagdollClient"
RagdollClientEvent.Parent = game.ReplicatedStorage

function tempragdoll(player,character)
	for _, v in pairs(character:GetDescendants()) do  --ragdoll
		if v:IsA("Motor6D") then
			local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
			a0.CFrame = v.C0
			a1.CFrame = v.C1
			a0.Parent = v.Part0
			a1.Parent = v.Part1
			local b = Instance.new("BallSocketConstraint")
			b.Attachment0 = a0
			b.Attachment1 = a1
			b.Parent = v.Part0
			v.Enabled = false
		end
	end
	wait(2)
	for _,v in pairs(character:GetDescendants()) do  --unragdoll
		if v:IsA('Motor6D') then
			v.Enabled = true
		end
		if v.Name == 'BallSocketConstraint' then
			v:Destroy()
		end
		if v.Name == 'Attachment' then
			v:Destroy()
		end
	end
	RagdollClientEvent:FireClient(player)
end



RagdollServerEvent.OnServerEvent:connect(tempragdoll)

The rbxl file containing them:

RtoRagdoll.rbxl (23.2 KB)

Hope you enjoy the script! No need to credit us or anything.

Bugs:
1.Moving mouse after Shift lock moves your character too while ragdolling. (I’ll try to patch it soon). This doesn’t happen in R6 however.
2. R6 ragdolling might trigger some weird camera movements (similar to gtaiv drunk camera motion) idk why this happens
Would really appreciate any help on this!

Edit 2:
Turns out I’m not only dumb, but also BLIND. Here’s another R to Ragdoll script that has a similar approach but different unragdoll function (tbh this script was very hard to find as the post isn’t tagged under ragdoll): How can i make a "R to Ragdoll" script? - #3 by Gusshiy

63 Likes

Wow awesome I was trying to do toggleable ragdoll but does this work in r6?

3 Likes

Yep, it cycles through whatever Motor6D the character has, so it will work on any form of avatar

3 Likes

Looks cool! I’ll try it out when I get back to my PC. I’m at school rn scrolling through the Forums XD

10 Likes

This only kills the player because humanoid.RequiresNeck is set to true by default. You can simply fix this by referencing the player’s humanoid and doing humanoid.RequiresNeck = false

2 Likes

This ragdoll system vs one I found in an old game I made

2 Likes

I guess disabling wrists, ankles, waist and root is not quite optimal lol. Should probably turn
off autoRotate and turn on canCollide of each part as well. I’m quite shocked that the body doesn’t respond to physics at 100 walkSpeed. I’m thinking of making another ragdoll system (this time by myself hopefully) with better replication so that the server doesn’t have to do any work. I’ll try to address these things in that one. Anyways, Thanks for sharing!

2 Likes

Hi! In that picture, is that this script or your old one? If it is your old one could you please send it! (if its ok with you)

2 Likes

Hi, it is in the devforum: R15 / Rthro Ragdolls

1 Like

This seems to be working perfectly, thanks! x

1 Like

Note to anyone looking at this script in the future this is exploitable. You should get the character from the player not sending it via the remote event.

Anyone still using this and needs a tip for the wonky camera, set the Camera Subject to the player’s head using the Local Script. The camera defaults to following the humanoid, which is based on the general position of the limbs, causing it to circle around. Focusing it on the Head will cause this problem to disappear.