How can i make a "R to Ragdoll" script?

I am currently making a roleplay game, and the people in it keep asking for me to add a “R to Ragdoll” feature, but i don’t know how to make it and i didn’t find anything that helped me in the Forums, can anyone help me?

13 Likes

You would start by cloning the character, and then manually making joints (in the script) that are able to be freely affected by physics.

2 Likes

After hours of trying to figure out the problem, I figured it out. First, make a folder in ReplicatedStorage named,“RemoteEvents” and put two RemoteEvents in it, one called “Ragdoll” and the other called"UnRagdoll". Next, put a localscript into StarterCharacterScripts and use this code:

--Variables--
local UIS = game:GetService("UserInputService")
local RemoteEvents = game.ReplicatedStorage.RemoteEvents
local CAS = game:GetService("ContextActionService")
local FreezeAction = "freezeMovement"
Ragdoll = false
--R detection script
UIS.InputBegan:Connect(function(KeyPressed)
	if KeyPressed.KeyCode == Enum.KeyCode.R then
		if not Ragdoll then
			CAS:BindAction(
				FreezeAction,
				function()
					return Enum.ContextActionResult.Sink
				end,
				false,
				unpack(Enum.PlayerActions:GetEnumItems())
			)
			RemoteEvents.Ragdoll:FireServer()
			print("Ragdolled")
			wait(0.5)
			Ragdoll = true
		else
			RemoteEvents.UnRagdoll:FireServer()
			CAS:UnbindAction(FreezeAction)
			print("Unragdolled")
			wait(0.5)
			Ragdoll = false
		end
	end
end)

Now that you got your first script, make another script in ServerScriptService and put this script in it:

--Variables--
local RagdollEvent = game.ReplicatedStorage.RemoteEvents.Ragdoll
local UnRagdollEvent = RagdollEvent.Parent.UnRagdoll
--Ragdoll script--
RagdollEvent.OnServerEvent:Connect(function(Player)
	for i,v in pairs(Player.Character:GetDescendants()) do
		if v:IsA("Motor6D") and v.Parent.Name ~= "HumanoidRootPart" then
			local Socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = v.Part0
			a2.Parent = v.Part1
			Socket.Parent = v.Parent
			Socket.Attachment0 = a1
			Socket.Attachment1 = a2
			a1.CFrame = v.C0
			a2.CFrame = v.C1
			Socket.LimitsEnabled = true
			Socket.TwistLimitsEnabled = true
			v:Destroy()
		end
	end
	Player.Character.Humanoid.RequiresNeck = false
	Player.Character.Humanoid.Sit = true
end)
--Unragdoll script--
UnRagdollEvent.OnServerEvent:Connect(function(Player)
	for i,v in pairs(Player.Character:GetDescendants()) do
		if v:IsA("BallSocketConstraint") then
			v.UpperAngle = 0
			v.TwistUpperAngle = 0
			v.TwistLowerAngle = 0
			local Joints = Instance.new("Motor6D",v.Parent)
			Joints.Part0 = v.Attachment0.Parent
			Joints.Part1 = v.Attachment1.Parent
			Joints.C0 = v.Attachment0.CFrame
			Joints.C1 = v.Attachment1.CFrame
			v:Destroy()
		end
	end
	Player.Character.Humanoid.Sit = false
end)

Now it should work. I made these scripts just for this problem. It works better if you use r6 instead of r15. If you use r15, you might be able to perfect it with some tweaking. Happy holidays! I hope this helped!

66 Likes

Anything accessible to the client is theoretically exploitable (including module scripts). Additionally, I don’t see why anyone would want to unnaturally fire the remote event used, if that is what you’re talking about by saying “exploitable”.

8 Likes

It would work better if in the local script u put:

--Variables--
local UIS = game:GetService("UserInputService")
local RemoteEvents = game.ReplicatedStorage.RemoteEvents
local CAS = game:GetService("ContextActionService")
local FreezeAction = "freezeMovement"
Ragdoll = false
local Player = game.Players.LocalPlayer
local CamSubjectBefore
--R detection script
UIS.InputBegan:Connect(function(KeyPressed)
	if KeyPressed.KeyCode == Enum.KeyCode.R then
		if not Ragdoll then
			CAS:BindAction(
				FreezeAction,
				function()
					return Enum.ContextActionResult.Sink
				end,
				false,
				unpack(Enum.PlayerActions:GetEnumItems())
			)
			RemoteEvents.Ragdoll:FireServer()
			wait(0.5)
			Ragdoll = true
			Player.Character.Humanoid.PlatformStand = true
			Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
			Player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
			CamSubjectBefore = Player.Character.Humanoid
			game.Workspace.CurrentCamera.CameraSubject = Player.Character.Head


		else
			RemoteEvents.UnRagdoll:FireServer()
			CAS:UnbindAction(FreezeAction)
			wait(0.5)
			Ragdoll = false
			Player.Character.Humanoid.PlatformStand = false

			wait()
			Player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
			game.Workspace.CurrentCamera.CameraSubject = CamSubjectBefore

			

		end
	end
end)

and in the server script u put:

--Variables--
local RagdollEvent = game.ReplicatedStorage.RemoteEvents.Ragdoll
local UnRagdollEvent = RagdollEvent.Parent.UnRagdoll

--Ragdoll script--
RagdollEvent.OnServerEvent:Connect(function(Player)
	for i,v in pairs(Player.Character:GetDescendants()) do
		if v:IsA("Motor6D") and v.Parent.Name ~= "HumanoidRootPart" and v.Parent.Name ~= "Head" then
			local Socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = v.Part0
			a2.Parent = v.Part1
			Socket.Parent = v.Parent
			Socket.Attachment0 = a1
			Socket.Attachment1 = a2
			a1.CFrame = v.C0
			a2.CFrame = v.C1
			Socket.LimitsEnabled = true
			Socket.TwistLimitsEnabled = true
			v:Destroy()
		end
	end
	Player.Character.Humanoid.RequiresNeck = false
	Player.Character.HumanoidRootPart.CanCollide = false


end)
--Unragdoll script--
UnRagdollEvent.OnServerEvent:Connect(function(Player)
	for i,v in pairs(Player.Character:GetDescendants()) do
		if v:IsA("BallSocketConstraint") then
			v.UpperAngle = 0
			v.TwistUpperAngle = 0
			v.TwistLowerAngle = 0
			local Joints = Instance.new("Motor6D",v.Parent)
			Joints.Part0 = v.Attachment0.Parent
			Joints.Part1 = v.Attachment1.Parent
			Joints.C0 = v.Attachment0.CFrame
			Joints.C1 = v.Attachment1.CFrame
			v:Destroy()
		end
	end
	Player.Character.Humanoid.RequiresNeck = true
	Player.Character.HumanoidRootPart.CanCollide = true


this one destroy the motor6d in the serverscript, i guse when unragdolling you gonna only have torso and neck

recommend using .Enabled
post must be 123213

robloxapp-20231203-2011334.wmv (731.9 KB)

This works, however, when the Character ragdolls, it appears to be “shivering”. Is there a way to make it just fall like it passed out?

2 Likes

Could you explain why you are using context action service?