Strange Ragdoll

Here is the video:
Video

I wanna know why the Ragdoll is strange and sometimes keep shaking and the body part sometimes flow in the air which cannot place on the ground. How to improve the ragdoll?
Here is the code:

local Ragdoll = {}

function Ragdoll.EnableRagdoll(character)
	local Humanoid = character:WaitForChild("Humanoid")

	Humanoid.RequiresNeck = false
	Humanoid.PlatformStand = true
	Humanoid.AutoRotate = false
	Humanoid.WalkSpeed = 0
	Humanoid.JumpHeight = 0
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

	for _, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local part0 = joint.Part0
			local part1 = joint.Part1

			if part0 and part1 then
				local BallSocketConstraint = Instance.new("BallSocketConstraint", joint.Parent)
				local Attachment0 = Instance.new("Attachment", part0)
				local Attachment1 = Instance.new("Attachment", part1)
				Attachment0.Name = "TempAttachment"
				Attachment1.Name = "TempAttachment"

				Attachment0.CFrame = joint.C0
				Attachment1.CFrame = joint.C1

				BallSocketConstraint.Attachment0 = Attachment0
				BallSocketConstraint.Attachment1 = Attachment1
				--BallSocketConstraint.LimitsEnabled = true
				--BallSocketConstraint.UpperAngle = 10

				joint.Enabled = false
			end
		end
	end

	for _, bodyPart in pairs(character:GetChildren()) do
		if bodyPart:IsA("MeshPart") then
			local CollideBox = Instance.new("Part", bodyPart)
			CollideBox.Size = Vector3.new(bodyPart.Size.X, bodyPart.Size.Y / 2, bodyPart.Size.Z) 
			CollideBox.CFrame = bodyPart.CFrame
			CollideBox.Transparency = 1
			CollideBox.CanCollide = true
			CollideBox.Massless = true
			CollideBox.Name = "TempCollideBox"

			local Weld = Instance.new("Weld", CollideBox)
			Weld.Name = "TempWeld"
			Weld.Part0 = CollideBox
			Weld.Part1 = bodyPart
		end
	end
end

function Ragdoll.DisableRagdoll(character)
	local Humanoid = character:WaitForChild("Humanoid")

	for _, items in pairs(character:GetDescendants()) do
		if items:IsA("Motor6D") then
			items.Enabled = true
		end
		if items:IsA("Attachment") and items.Name == "TempAttachment" then
			items:Destroy()
		end
		if items:IsA("Part") and items.Name == "TempCollideBox" then
			items:Destroy()
		end
		if items:IsA("Weld") and items.Name == "TempWeld" then
			items:Destroy()
		end
	end

	Humanoid.RequiresNeck = true
	Humanoid.PlatformStand = false
	Humanoid.AutoRotate = true
	Humanoid.WalkSpeed = 16
	Humanoid.JumpHeight = 7.2
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end


return Ragdoll

Thank you

1 Like

Add the players limbs to a collision group so that it can collide with the ground but not its self, it should fix the weird stuck in the air thing

1 Like