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?
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