Ragdoll Collision Trouble

I made a module that ragdolls the character given, but the character’s limbs no-clip through the ground after a while when it’s ragdolled:

Here’s a clip of what occurs:

Here’s the module that i made:

local Tools = {}
function Tools.Ragdoll(Char: Model)
	
	if Char.ClassName ~= "Model" then
		return
	end
	
	if Char:IsA("Model") then
		for i, v in pairs(Char:GetDescendants()) do		

			local Humanoid = Char:FindFirstChildOfClass("Humanoid")
			Humanoid:ChangeState(Enum.HumanoidStateType.Physics, true)
			
			Humanoid.AutoRotate = false; Humanoid.PlatformStand = true
			
			if v:IsA("Motor6D") then
				local Socket = Instance.new('BallSocketConstraint')
				
				local Attach0 = Instance.new("Attachment")
				
				local Attach1 = Instance.new("Attachment")
				Attach0.Parent = v.Part0; Attach1.Parent = v.Part1
				
				Socket.Parent = v.Parent; Socket.Attachment0 = Attach0; Socket.Attachment1 = Attach1
				
				Attach0.CFrame = v.C0; Attach1.CFrame = v.C1				
				Socket.LimitsEnabled = true; Socket.TwistLimitsEnabled = true; v.Enabled = false
			end
		end
		
		for i, v in pairs(Char:GetChildren()) do
			
			if v:IsA("MeshPart") or v:IsA("Part") then
				v.Anchored = false; v.CanCollide = false
			end
		end
		
		
	end
end
function Tools.Stop(Char: Model)
	
	local Humanoid = Char:FindFirstChildOfClass("Humanoid")
	Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	
	if Char.ClassName ~= "Model" then
		return
	end
	
	for i, v in pairs(Char:GetDescendants()) do
		
		if v:IsA("BallSocketConstraint") then		
			v:Destroy()		
		end
		
		if v:IsA("Motor6D") then		
			v:Destroy()
		end
	end
	
	for i, v in pairs(Char:GetChildren()) do
		if v:IsA("BasePart") or v:IsA("Part") or v:IsA("MeshPart") then

			v.CanCollide = false
		end
		
	end
end

return Tools

Any help is appreciated!

2 Likes

The arms and legs of default roblox characters don’t have collisions enabled. You would need to do this through a script.

Thanks a lot, I can continue with my game now!

You should change the collision of the parts to true upon ragdolling. I’d also recommend using NoCollisionConstraints to prevent collisions between body parts, which can prevent spasms.

You also shouldn’t set Humanoid.PlatformStand to true; it overrides the Physics state that you set earlier in the script, which can cause the phasing through the floor you described earlier.

Here’s what it would look like after the additions:

local Tools = {}
function Tools.Ragdoll(Char: Model)
	
	if Char.ClassName ~= "Model" then
		return
	end
	
	if Char:IsA("Model") then
		for i, v in pairs(Char:GetDescendants()) do		

			local Humanoid = Char:FindFirstChildOfClass("Humanoid")
			Humanoid:ChangeState(Enum.HumanoidStateType.Physics,)
			
			Humanoid.AutoRotate = false; 
			
			if v:IsA("Motor6D") then
				local Socket = Instance.new('BallSocketConstraint')
				
				local Attach0 = Instance.new("Attachment")
				
				local Attach1 = Instance.new("Attachment")
				Attach0.Parent = v.Part0; Attach1.Parent = v.Part1
				
				Socket.Parent = v.Parent; Socket.Attachment0 = Attach0; Socket.Attachment1 = Attach1
				
				Attach0.CFrame = v.C0; Attach1.CFrame = v.C1				
				Socket.LimitsEnabled = true; Socket.TwistLimitsEnabled = true; v.Enabled = false
				
				local NoCollisionConstraint = Instance.new('NoCollisionConstraint')
				NoCollisionConstraint.Part0, NoCollisionConstraint.Part1 = v.Part0, v.Part1
				NoCollisionConstraint.Parent = v.Part0
			end
		end
		
		for i, v in pairs(Char:GetChildren()) do
			
			if v:IsA("MeshPart") or v:IsA("Part") then
				v.Anchored = false; v.CanCollide = true
			end
		end
		
		
	end
end
function Tools.Stop(Char: Model)
	
	local Humanoid = Char:FindFirstChildOfClass("Humanoid")
	Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	
	if Char.ClassName ~= "Model" then
		return
	end
	
	for i, v in pairs(Char:GetDescendants()) do
		
		if v:IsA("BallSocketConstraint") then		
			v:Destroy()		
		end
		
		if v:IsA("Motor6D") then		
			v:Destroy()
		end
	end
	
	for i, v in pairs(Char:GetChildren()) do
		if v:IsA("BasePart") or v:IsA("Part") or v:IsA("MeshPart") then

			v.CanCollide = false
		end
		
	end
end

return Tools
1 Like

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