Hello! This short tutorial will teach you how to make a ragdoll death for R15 and R6 in one script. Let's get started!
This wil be a normal script, not a local script. Put this script in StarterCharacterScripts, which is inside of the StarterPlayer.
The main variable is what detects if the character died or not, and this script won't work without it:
local humanoid = script.Parent:WaitForChild("Humanoid")
Right under this we're gonna put another line of code:
humanoid.BreakJointsOnDeath = false
This needs to stay false; your character won't ragdoll if you change it.
This is what starts it all. A simple line of code that detects when the player dies:
humanoid.Died:Connect(function()
end)
##The for and if Loops Inside of the silent function we're gonna put a for and if statement:
for index, joint in pairs(script.Parent:GetDecendants()) do
if joint:IsA("Motor6D") then
end
end
Make sure these variables are put inside of the if statement:
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
The new instances need to be parented to something:
a1.Parent = joint.Part0
a2.Parent = joint.Part1
socket.Parent = joint.Parent
The variables a1 and a2 are attachments. They need to be attached to something. So here we're attaching them to the ball socket constraint:
socket.Attachment0 = a1
socket.Attachment1 = a2
The attachments' positions need to be set:
a1.CFrame = joint.C0
a2.CFrame = joint.C1
The CFrame of a part is bascally the position and the rotation. It's used in most cases. The 0 in joint.C0 isn't an O, it's a zero.
This is basically how flexible the ragdoll is:
socket.LimitsEnabled = false -- change this to your liking
socket.TwistLimitsEnabled = true -- change this to your liking
You shouldn't get rid of this:
joint:Destroy()
##End Result The end result should look like this:
local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function()
for index, joint in pairs(script.Parent:GetDecendants())
if joint:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint")
local a1 = Instance.new("Attachment")
local a2 = Instance.new("Attachment")
a1.Parent = joint.Part0 -- this is a zero
a2.Parent = joint.Part1
socket.Parent = joint.Parent
socket.Attachment0 = a1 -- Attachment zero
socket.Attachment1 = a2
a1.CFrame = joint.C0 -- this is a zero
a2.CFrame = joint.C1
socket.LimitsEnabled = false -- change this to your liking
socket.TwistLimitsEnabled = true -- change this to your liking
joint:Destroy()
end
end
end)
If your result doesn't look like this, you should fix it.
That is how to make a ragdoll death for R6 and R15 in one script. It's a very simple code. Thank you for reading this! I hope you learned something and thought this was useful. I will see you again in the next tutorial. Bye!