Ragdoll Script not working

Hello! I’ve tried many things and cannot seem to get this ragdoll script to work correct it does this:
RobloxStudioBeta_CxEwcZsJo8
My code:

local function RagDoll(Character,waitTime)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	for _, descendant in ipairs(Character:GetDescendants()) do
		if descendant:IsA("Motor6D") and descendant.Parent.Name ~= "HumanoidRootPart" then
			local joint_name = descendant.Name
			local part0 = descendant.Part0
			local attachment0 = descendant.Parent:FindFirstChild(joint_name.."Attachment") or descendant.Parent:FindFirstChild(joint_name.."RigAttachment")
			local attachment1 = part0:FindFirstChild(joint_name.."Attachment") or part0:FindFirstChild(joint_name.."RigAttachment")

			if attachment0 and attachment1 then
				local socket = Instance.new("BallSocketConstraint")
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true
				socket.Attachment0, socket.Attachment1 = attachment0, attachment1
				socket.UpperAngle = 5
				socket.Parent = descendant.Parent

				descendant.Enabled = false
			end
		end
	
		if descendant:IsA("BasePart") and descendant:FindFirstChildOfClass("Motor6D") and Character.Humanoid:GetLimb(descendant) ~= Enum.Limb.Unknown then
			descendant.CanCollide = true
		end
	end
	task.wait(waitTime)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	for i,v in ipairs(Character:GetDescendants()) do
		if v:IsA("Motor6D") then
			v.Enabled = true
		elseif v:IsA("BallSocketConstraint") then
			v:Destroy()
		end
	end
end
1 Like

Try using Enum.HumanoidStateType.Physics instead of Enum.HumanoidStateType.Ragdoll

1 Like

RobloxStudioBeta_xBPtEdsBxT

Is this on a server or local script? Anything that is changing the state of the player’s character should be done locally.

I am testing this on my self in a server script, where it’ll be used for hitboxes

Retried this my usual module setup, it worked

1 Like