Abrah_m's Ragdoll System V1 [Open-Sourced]

Intro


Hello DevForums! My name is abrah_m.

So basically, I was making a game, and wanted to implement a ragdoll system. I ended up making one, but it just seemed wrong. I kept writing the same ‘long’ lines of codes to make the player ragdoll. Then I came up with an idea for a simple ragdoll system. I also wanted to give back to the community somehow, and found this as a perfect oppurtunity to do so. This project didn’t take long, although I came across some bugs which I fixed. In this post, I will link the system, and explain how to use it!

And yes, it is compatible with R6 and R15.



How To Use // How it Works


What makes this system different from others is that, this one, is the simplest I’ve seen. So, how do you use it?

rag1

When the game loads, a bool value is added inside of the character (The value is inserted through the ‘Values’ script). When the value is set to true on a ServerSided script, it will ragdoll the character the value is parented to.

Example:

R to Ragdoll Script:

Note: How the code works is explained inside of each of the script. There is also a RemoteEvent in ReplicatedStorage making this work, alongside, there’s other things that make this script work like guis

Client:

local UserInputService = game:GetService("UserInputService"); -- Gets Input Service

local Toggle = false; -- Value to see whether toggled or not

script.Parent.MouseButton1Click:Connect(function() -- script.Parent is the gui, function runs lines below it when gui is clicked
	if not Toggle then -- Checks if gui toggled or not
		Toggle = true; -- If not, toggle is set to true
		
		game.ReplicatedStorage.Events.Ragdoll:FireServer(true) -- Fires event to server saying toggle is on
	else -- If Toggle is true, the lines under this will play
		Toggle = false; -- Toggle becomes false if set to true
		
		game.ReplicatedStorage.Events.Ragdoll:FireServer(false) -- Fires event to server saying toggle is off
	end
end)

UserInputService.InputBegan:Connect(function(input, typing) -- Same goes for code above except it's when your press R instead of clicking gui
	if input.KeyCode == Enum.KeyCode.R and not typing then -- Change R to keybind you want
		if not Toggle then
			Toggle = true;

Server:

game.ReplicatedStorage.Events.Ragdoll.OnServerEvent:Connect(function(Player, Toggle) -- Player is the player, and toggle is the value that was fired from the client to the server
	local Character = Player.Character or Player.CharacterAdded:Wait() -- Gets the player model of the player
	
	if Toggle == true then -- If the value that was transferred over to this server script was true, then the 'IsRagdoll' value will be set to true
		Character:WaitForChild("IsRagdoll").Value = true; -- Ragdoll value inside of character is set to true, causing character to ragdoll
	else
		Character:WaitForChild("IsRagdoll").Value = false; -- Un-ragdolls player after it is set back to false
	end
end)

What the R to Ragdoll script ends up with and other stuff:


Download/Demo


Download: Ragdoll Open Source.rbxl (33.2 KB)

Un-Copylocked Game: Ragdoll Open Source - Roblox

29 Likes

Looks very good. How do you make this?

1 Like

Basically, I made it so that it detects when the ‘IsRagdoll’ value changes using :GetPropertyChangedSignal("Value"). The ‘IsRagdoll’ value is inserted through a ServerScript in ServerScriptService, when the character loads. I put this both client and server sided, so in the server (if value is true), the motor6ds disables and gets replaces with BallSocketConstraints, and on the client, the HumanoidStateType changes to ragdoll and getting up gets disabled. If value is set false, it reverses the effect, removing the constraints, and attachments, and re-enables the motor6ds, also in client, it enables getting up.

2 Likes

This reminds me of this other guy’s implementation. I’ve got a few tips for improvements:

  • Consider using Attributes instead of ObjectValues (kind of a personal preference thing)
  • Consider de-activating the constraint instead of deleting and re-creating it every time
1 Like

Thanks for the ideas! I will make sure to implement those in v2 soon. :slightly_smiling_face:

Roblox has a simple ragdoll module

2 Likes

@abrah_m This is really cool thanks!

2 Likes

but I kinda need this module now cuz it only works for classic roblox characters :sleepy: