How do i will make a ragdoll script/module

Hi everyone, who reading this! :partying_face:

I’m interested on making a simple module with a:

  • Ragdoll (for sure).
  • Timer of Ragdoll.
  • Thats all would be working on players and on NPC.

I just need a theory of this script, like what i should use to make a ragdoll, like objects, methods, etc. to make a good ragdoll.

2 Likes

Edit: I know how to make a timer for a ragdoll :slight_smile:
but not other things :frowning:

1 Like

does anyone know how to do thats?

but would someone still answer on it…?

Hey there! In roblox, ragdoll is made via looping through the character’s Motor6Ds, and disabling them. (via for loop). Motor6Ds have C0, Part0, C1, and Part1 attributes. Make 2 Attachments via script and parent the first Attachment to Part0, and the second Attachment to Part1. Then, set the CFrame attribute for Attachment 1 to C0, and set Attachment 2s CFrame to, you guessed it… C1. Then, make a BallSocketConstraint. Set attachment0 to our first Attachment and attachment1 to our second Attachment. Then set LimitsEnabled and TwistLimitsEnabled to true, and parent the BallSocketConstraint to the parent of the Motor6D.

To disable ragdoll, you would need to destroy all Attachments and BallSocketConstraints that do our ragdoll, enabling all Motor6Ds in the process.

A handy module for this would look somewhat like the following…

local ragdollHandler = {}

function ragdollHandler:ragdoll(character, duration)
	for index, joint in pairs(character:GetDescendants()) do -- Loop Through Every Descendant of the Character
		if joint:IsA("Motor6D") then -- Is the Joint a Motor6D?
			local attachment1 = Instance.new("Attachment") -- Attachment 1
			attachment1.Name = "Ragdoll Attachment"
			attachment1.CFrame = joint.C0
			attachment1.Parent = joint.Part0

			local attachment2 = Instance.new("Attachment") -- Attachment 2
			attachment2.Name = "Ragdoll Attachment"
			attachment2.CFrame = joint.C1
			attachment2.Parent = joint.Part1

			local socket = Instance.new("BallSocketConstraint") -- Make a BallSocketConstraint
			socket.Name = "Ragdoll BallSocketConstraint"
			socket.Attachment0 = attachment1 -- Set "attachment0" to the first attachment we made
			socket.Attachment1 = attachment2 -- Set "attachment1" to the second attachment we made
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			socket.Parent = joint.parent -- Parent the BallSocketConstraint to Motor6Ds parent

			joint.Enabled = false

			task.delay(duration, function() -- In a separate thread, after our duration, disable ragdoll
				socket:Destroy()
				attachment1:Destroy()
				attachment2:Destroy()
				
				joint.Enabled = true
			end)
		end
	end
end

return ragdollHandler
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.