Help with 'F to ragdoll'

I’m testing with ragdolls right now and making an ‘F to ragdoll’ script (I haven’t made the unragdoll part yet). I got the ragdoll on death script and most of the control script from a youtube video. And I have a problem that I don’t know how to fix or troubleshoot.


When I press F it goes into a weird state that I can still control and its hovering off the ground slightly, but the ragdoll on death works greatly. This problem also happens with R6 aswell. Here are the scripts and explorer tab:

Local Script (Controller)

local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local pchar = plr.Character
local deb = false
local rag = false
local ron = game.ReplicatedStorage.RagdollC.RagOn
local rof = game.ReplicatedStorage.RagdollC.RagOff

uis.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.F then
		if rag == false then
			if deb == false then
				rag = true
				deb = true
				ron:FireServer()
			end
		end
		if rag == false then
			if deb == false then
				rag = false 
				deb = true
				rof:FireServer()
			end
		end
		wait(.5)
		deb = false
	end
end)

Server Script (ragdoller)

local humanoid = script.Parent:WaitForChild("Humanoid")
local ragOn = game.ReplicatedStorage.RagdollC.RagOn
local ragOff = game.ReplicatedStorage.RagdollC.RagOff
local ragdolled = false

humanoid.BreakJointsOnDeath = false


-- die ragdoll
humanoid.Died:Connect(function()
	for i,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local soc = Instance.new("BallSocketConstraint")
			local a0 = Instance.new("Attachment")
			local a1 = Instance.new("Attachment")
			a0.Parent = joint.Part0
			a1.Parent = joint.Part1
			soc.Parent = joint.Parent
			soc.Attachment0 = a0
			soc.Attachment1 = a1
			a0.CFrame = joint.C0
			a1.CFrame = joint.C1
			soc.LimitsEnabled = true
			soc.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end
end)

-- f to ragdoll
ragOn.OnServerEvent:Connect(function(plr)
	local pchar = plr.Character
	local cfolder = Instance.new("Folder", game.ServerStorage)
	cfolder.Name = (plr.Name .. "'s Joints")
	for i,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local soc = Instance.new("BallSocketConstraint")
			local a0 = Instance.new("Attachment")
			local a1 = Instance.new("Attachment")
			local jclone = joint:Clone()
			jclone.Parent = cfolder
			print("Cloned")
			a0.Parent = joint.Part0
			a1.Parent = joint.Part1
			soc.Parent = joint.Parent
			soc.Attachment0 = a0
			soc.Attachment1 = a1
			a0.CFrame = joint.C0
			a1.CFrame = joint.C1
			soc.LimitsEnabled = true
			soc.TwistLimitsEnabled = true
			joint:Destroy()
			ragdolled = true
		end
	end
end)

Explorer

image

1 Like

Make a script and put it in serverscript service:

local RemoteEvent = Instance.new("RemoteEvent",game.ReplicatedStorage)
RemoteEvent.Name = "Ragdoll"

RemoteEvent.OnServerEvent:Connect(function(Player,RigType,Ragdolling)
	Player.Character.Humanoid.BreakJointsOnDeath = false
	if RigType == Enum.HumanoidRigType.R6 and Ragdolling == false then
		Player.Character.Humanoid.PlatformStand = true
		while Player.Character.Torso:FindFirstChildWhichIsA("Attachment") do
			script.Parent.Torso:FindFirstChildWhichIsA("Attachment"):Remove()
		end
		for i,v in pairs(Player.Character.Torso:GetChildren()) do
			if v.ClassName == "Motor6D" then
				v.Enabled = false
			end
		end
		for i,v in pairs(Player.Character:GetChildren()) do
			if v.ClassName == "Part" then
				v.CanCollide = true
			end
		end
		local HA1 = Instance.new("Attachment",script.Parent.Head)
		local HA2 = Instance.new("Attachment",script.Parent.Torso)
		local RAA1 = Instance.new("Attachment",script.Parent["Right Arm"])
		local RAA2 = Instance.new("Attachment",script.Parent.Torso)
		local LAA1 = Instance.new("Attachment",script.Parent["Left Arm"])
		local LAA2 = Instance.new("Attachment",script.Parent.Torso)
		local RLA1 = Instance.new("Attachment",script.Parent["Right Leg"])
		local RLA2 = Instance.new("Attachment",script.Parent.Torso)
		local LLA1 = Instance.new("Attachment",script.Parent["Left Leg"])
		local LLA2 = Instance.new("Attachment",script.Parent.Torso)
		
		local HC = Instance.new("BallSocketConstraint",script.Parent.Torso)
		local RAC = Instance.new("BallSocketConstraint",script.Parent.Torso)
		local LAC = Instance.new("BallSocketConstraint",script.Parent.Torso)
		local RLC = Instance.new("BallSocketConstraint",script.Parent.Torso)
		local LLC = Instance.new("BallSocketConstraint",script.Parent.Torso)
		
		HA1.Position = Vector3.new(0,-0.5,0)
		RAA1.Position = Vector3.new(-0.5,1,0)
		LAA1.Position = Vector3.new(0.5,1,0)
		RLA1.Position = Vector3.new(0,1,0)
		LLA1.Position = Vector3.new(0,1,0)
		
		HA2.Position = Vector3.new(0,1,0)
		RAA2.Position = Vector3.new(1,1,0)
		LAA2.Position = Vector3.new(-1,1,0)
		RLA2.Position = Vector3.new(0.5,-1,0)
		LLA2.Position = Vector3.new(-0.5,-1,0)
		
		HC.Attachment0 = HA2
		HC.Attachment1 = HA1
	
		RAC.Attachment0 = RAA2
		RAC.Attachment1 = RAA1
		
		LAC.Attachment0 = LAA2
		LAC.Attachment1 = LAA1
	
		RLC.Attachment0 = RLA2
		RLC.Attachment1 = RLA1
	
		LLC.Attachment0 = LLA2
		LLC.Attachment1 = LLA1
	elseif RigType == Enum.HumanoidRigType.R6 and Ragdolling == true then
		Player.Character.PlatformStand = false
		for i,v in pairs(Player.Character.Torso:GetChildren()) do
			if v.ClassName == "Motor6D" then
				v.Enabled = true
			end
		end
	elseif RigType == Enum.HumanoidRigType.R15 and Ragdolling == false then
		Player.Character.Humanoid.PlatformStand = true
		Player.Character.Head:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.UpperTorso:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LowerTorso:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightUpperArm:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightLowerArm:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightHand:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftUpperArm:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftLowerArm:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftHand:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightUpperLeg:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightLowerLeg:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.RightFoot:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftUpperLeg:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftLowerLeg:FindFirstChildWhichIsA("Motor6D").Enabled = false
		Player.Character.LeftFoot:FindFirstChildWhichIsA("Motor6D").Enabled = false
		
		local HC = Instance.new("BallSocketConstraint",Player.Character.UpperTorso)
		local TC = Instance.new("BallSocketConstraint",Player.Character.LowerTorso)
		local RUAC = Instance.new("BallSocketConstraint",Player.Character.UpperTorso)
		local RLAC = Instance.new("BallSocketConstraint",Player.Character.RightUpperArm)
		local RHC = Instance.new("BallSocketConstraint",Player.Character.RightLowerArm)
		local LUAC = Instance.new("BallSocketConstraint",Player.Character.UpperTorso)
		local LLAC = Instance.new("BallSocketConstraint",Player.Character.LeftUpperArm)
		local LHC = Instance.new("BallSocketConstraint",Player.Character.LeftLowerArm)
		local RULC = Instance.new("BallSocketConstraint",Player.Character.LowerTorso)
		local RLLC = Instance.new("BallSocketConstraint",Player.Character.RightUpperLeg)
		local RFC = Instance.new("BallSocketConstraint",Player.Character.RightLowerLeg)
		local LULC = Instance.new("BallSocketConstraint",Player.Character.LowerTorso)
		local LLLC = Instance.new("BallSocketConstraint",Player.Character.LeftUpperLeg)
		local LFC = Instance.new("BallSocketConstraint",Player.Character.LeftLowerLeg)
		
		HC.Attachment0 = Player.Character.UpperTorso.NeckRigAttachment
		HC.Attachment1 = Player.Character.Head.NeckRigAttachment
		TC.Attachment0 = Player.Character.LowerTorso.WaistRigAttachment
		TC.Attachment1 = Player.Character.UpperTorso.WaistRigAttachment
		RUAC.Attachment0 = Player.Character.UpperTorso.RightShoulderRigAttachment
		RUAC.Attachment1 = Player.Character.RightUpperArm.RightShoulderRigAttachment
		RLAC.Attachment0 = Player.Character.RightUpperArm.RightElbowRigAttachment
		RLAC.Attachment1 = Player.Character.RightLowerArm.RightElbowRigAttachment
		RHC.Attachment0 = Player.Character.RightLowerArm.RightWristRigAttachment
		RHC.Attachment1 = Player.Character.RightHand.RightWristRigAttachment
		LUAC.Attachment0 = Player.Character.UpperTorso.LeftShoulderRigAttachment
		LUAC.Attachment1 = Player.Character.LeftUpperArm.LeftShoulderRigAttachment
		LLAC.Attachment0 = Player.Character.LeftUpperArm.LeftElbowRigAttachment
		LLAC.Attachment1 = Player.Character.LeftLowerArm.LeftElbowRigAttachment
		LHC.Attachment0 = Player.Character.LeftLowerArm.LeftWristRigAttachment
		LHC.Attachment1 = Player.Character.LeftHand.LeftWristRigAttachment
		RULC.Attachment0 = Player.Character.LowerTorso.RightHipRigAttachment
		RULC.Attachment1 = Player.Character.RightUpperLeg.RightHipRigAttachment
		RLLC.Attachment0 = Player.Character.RightUpperLeg.RightKneeRigAttachment
		RLLC.Attachment1 = Player.Character.RightLowerLeg.RightKneeRigAttachment
		RFC.Attachment0 = Player.Character.RightLowerLeg.RightAnkleRigAttachment
		RFC.Attachment1 = Player.Character.RightFoot.RightAnkleRigAttachment
		LULC.Attachment0 = Player.Character.LowerTorso.LeftHipRigAttachment
		LULC.Attachment1 = Player.Character.LeftUpperLeg.LeftHipRigAttachment
		LLLC.Attachment0 = Player.Character.LeftUpperLeg.LeftKneeRigAttachment
		LLLC.Attachment1 = Player.Character.LeftLowerLeg.LeftKneeRigAttachment
		LFC.Attachment0 = Player.Character.LeftLowerLeg.LeftAnkleRigAttachment
		LFC.Attachment1 = Player.Character.LeftFoot.LeftAnkleRigAttachment
	elseif RigType == Enum.HumanoidRigType.R15 and Ragdolling == true then
		Player.Character.Humanoid.PlatformStand = false
		Player.Character.Head:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.UpperTorso:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LowerTorso:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightUpperArm:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightLowerArm:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightHand:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftUpperArm:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftLowerArm:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftHand:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightUpperLeg:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightLowerLeg:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.RightFoot:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftUpperLeg:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftLowerLeg:FindFirstChildWhichIsA("Motor6D").Enabled = true
		Player.Character.LeftFoot:FindFirstChildWhichIsA("Motor6D").Enabled = true
	end
end)

Now put this local script in ReplicatedFirst:

local UIS = game:GetService("UserInputService")

Ragdolling = false

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.F then
		Ragdolling = not Ragdolling
		if Ragdolling == false then
			workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Head
		elseif Ragdolling == true then
			workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
		end
		game.ReplicatedStorage:FindFirstChild("Ragdoll"):FireServer(game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").RigType,Ragdolling)
	end
end)
1 Like

This works with R15 kinda, the limbs spin around fastly and it doesn’t work at all in R6. Thanks for helping though :happy1:

Oh, I will get back to you with a fixed script if i can.

Hi! I was experimenting with the platform stand bool in the humanoid and the ragdoll works as intended for a couple seconds after disabling the property, Is there a way to lock this state while ragdolled?

I tried doing what you did but what i got was just a frozen ragdoll so i dont really know

(if i missed something in your code, i’m on mobile)

You should set the HumanoidState to Physics for it to be uncontrollable after ragdoll, and set it to GettingUp to unragdoll.

Edit 1: PlatformStand is only an indicator for a specific HumanoidStateType. It cannot be changed as far as i know.

I would recommend checking the state beforehand with Humanoid:GetState() and setting it with Humanoid:ChangeState(Enum.HumanoidStateType.Physics). One of theese is client sided.

State types here

Humanoid (look at functions, might seem a lot but it’s not)

Edit 2: I saw you destroying joints. There is a better way.

Motor6D has an Active value. You can just cycle trough and disable/enable them. And this goes for all joints.

You can just create BallInSocket joints to enable/disable too. There are already attachment points on the body. For instance: The LeftHand has a LeftGrip and a LeftWrist attachment. LeftUpperArm has LeftWrist and LeftElbow??? I think?. and so on. (You see how theese can be used.

Edit 3: I should clarify the first point. The LowerTorso is attached to the HumanoidRootPart. And the HumanoidRootPart just… floats above ground and moves accordingly if the HumanoidStateType allows it. HumanoidStateType.Physics disables this behaviour.

Aka: ragdoll-ish, “fall over like a plank” type beat. This is where your code should step in.

If i go home from school i'll help more. Feel free to start a chat.

This will be edited in the future. Come back in 15-30m intervals please.

I was here once before, and just want to help. :smile: