Ragdoll not colliding

Hi guys! I am making a ragdoll script, but it only seems to work when ragdolling a dead player.
Everything prints as intended, but when I check the properties during testing, and the CanCollide is off.

Any help? I can’t find anything…

The script is listed below:

Ragdoll Script
local module = {}

function module.Ragdoll(char) -- Defines ragdoll function
	if not char:FindFirstChild("Humanoid") then -- If does not contain a humanoid
		warn("Attempted to ragdoll " .. tostring(char) .. ", which is not a character") -- Warn it is not a character
	end
	
	local humanoid = char:WaitForChild("Humanoid") -- Defines humanoid
	humanoid.PlatformStand = true -- Puts character into a physics state
	
	for i, object in char:GetDescendants() do -- Get every class Motor6D in the character
		if object:IsA("Motor6D") then
			local attachment0 = Instance.new("Attachment") -- Create an attachment
			local attachment1 = Instance.new("Attachment") -- Create an another attachment
			
			attachment0.CFrame = object.C0 -- Sets attachment0 to the Motor6D CFrame 0
			attachment1.CFrame = object.C1 -- Sets attachment1 to the Motor6D CFrame 1
			attachment0.Parent = object.Part0 -- Sets attachment0 parent to the Motor6D Part 0
			attachment1.Parent = object.Part1 -- Sets attachment1 parent to the Motor6D Part 1
			attachment0.Name = "RagdollAttachment0" -- Names attachment0
			attachment1.Name = "RagdollAttachment1" -- Names attachment1
			
			local ballsocketconstraint = Instance.new("BallSocketConstraint") -- Creates a BallSocketConstraint
			ballsocketconstraint.Attachment0 = attachment0 -- Sets the contraint's attachment0 to attachment0
			ballsocketconstraint.Attachment1 = attachment1 -- Sets the contraint's attachment1 to attachment1
			ballsocketconstraint.Parent = object.Parent -- Sets the contraint's parent to the Motor6D parent
			
			object.Enabled = false -- Disables the Motor6D
			
			char:AddTag("Ragdolled") -- Adds a ragdolled tag
		elseif object:IsA("BasePart") then -- Gets all BaseParts
			if object.Name == "HumanoidRootPart" then
				continue
			elseif object.Parent == char then -- If it belongs to the character
				print("Making " .. tostring(object) .. " collidable...")
				object.CanCollide = true -- Makes the object collidable
			end
		end
	end
end

return module
1 Like

this is a strange bug, i managed to get this to work though:

local module = {}

function module.Ragdoll(char) -- Defines ragdoll function
	if not char:FindFirstChild("Humanoid") then -- If does not contain a humanoid
		warn("Attempted to ragdoll " .. tostring(char) .. ", which is not a character") -- Warn it is not a character
	end

	local humanoid = char:WaitForChild("Humanoid") -- Defines humanoid
	humanoid.PlatformStand = true -- Puts character into a physics state

	for i, object in pairs(char:GetDescendants()) do -- Get every class Motor6D in the character
		if object:IsA("Motor6D") then
			local attachment0 = Instance.new("Attachment") -- Create an attachment
			local attachment1 = Instance.new("Attachment") -- Create an another attachment

			attachment0.CFrame = object.C0 -- Sets attachment0 to the Motor6D CFrame 0
			attachment1.CFrame = object.C1 -- Sets attachment1 to the Motor6D CFrame 1
			attachment0.Parent = object.Part0 -- Sets attachment0 parent to the Motor6D Part 0
			attachment1.Parent = object.Part1 -- Sets attachment1 parent to the Motor6D Part 1
			attachment0.Name = "RagdollAttachment0" -- Names attachment0
			attachment1.Name = "RagdollAttachment1" -- Names attachment1

			local ballsocketconstraint = Instance.new("BallSocketConstraint") -- Creates a BallSocketConstraint
			ballsocketconstraint.Attachment0 = attachment0 -- Sets the contraint's attachment0 to attachment0
			ballsocketconstraint.Attachment1 = attachment1 -- Sets the contraint's attachment1 to attachment1
			ballsocketconstraint.Parent = object.Parent -- Sets the contraint's parent to the Motor6D parent
			
			ballsocketconstraint.LimitsEnabled = true
			ballsocketconstraint.UpperAngle = 80
			--just to limit the bend angle
			
			for i, limb in pairs(char:GetDescendants()) do
				if limb:IsA("Basepart") then
					local nc = Instance.new("NoCollisionConstraint")
					nc.Part0 = object
					nc.Part1 = limb
					nc.Parent = object
				end
			end
			object.Enabled = false -- Disables the Motor6D

			char:AddTag("Ragdolled") -- Adds a ragdolled tag
		end
	end
	local measurelimb = char:FindFirstChild("LeftLeg")
	if not measurelimb then measurelimb = char:FindFirstChild("LeftUpperLeg") end
	repeat
		print("making characterr collidable")
		for i, object in pairs(char:GetDescendants()) do
			if object:IsA("BasePart") and object.Name ~= "HumanoidRootPart" then
				--print("Making " .. tostring(object) .. " collidable...")
				object.CanCollide = true
			end
		end
		wait()
	until measurelimb.CanCollide
end

return module

it appears that you cant set the CanCollide property too quickly as it does not work, so this loops until it does have collision.

2 Likes

After reading this, I used task.wait(0.1), and this solved the whole issue. I think this might be better, as it uses less memory.

Thank you for the information about the CanCollide property!

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