Players CanCollide turning false automatically (Ragdoll)

I am having an issue with CanCollide turning false occasionally with ragdoll, I have tried multiple things such as repeat CanCollide = true until

I did have it working with this solution as I added a delay to it but I am not happy the way I have done it so I deleted it because it will not always work 100% of the time

Any help is very appreciated

ModuleScript - Fired in LocalScript

function ToolManagement.Ragdoll(duration)
	--humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
	if RagdollDebounce == false then
		RagdollDebounce = true
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

		humanoid.RequiresNeck = false
		humanoid.AutoRotate = false
		humanoid.PlatformStand = true

		humanoid.WalkSpeed = 0

		Torso.RotVelocity = Vector3.new()

		game.ReplicatedStorage.Ragdoll:FireServer(duration)

		task.wait(duration)

		humanoid.RequiresNeck = true
		humanoid.AutoRotate = true
		humanoid.PlatformStand = false

		humanoid.WalkSpeed = 19

		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

		task.wait(1)
		RagdollDebounce = false
	end
end

Server Script

  if RagdollDebounce == false then
		
		RagdollDebounce = true
		
		player.Character:WaitForChild("Humanoid").RequiresNeck = false
		
		
		print("Set")

		for _, v in pairs(player.Character:GetDescendants()) do
			if v:IsA("Motor6D") then

				v.Enabled = false -- Disabled Motor6D

				local BallSocketConstraint = Instance.new("BallSocketConstraint", v.Parent)
				BallSocketConstraint.Name = v.Name

				game:GetService("Debris"):AddItem(BallSocketConstraint, duration)

				local Attachment0 = Instance.new("Attachment", v.Part0)
				Attachment0.Name = "Attachment0"

				game:GetService("Debris"):AddItem(Attachment0, duration)

				local Attachment1 = Instance.new("Attachment", v.Part1)
				Attachment1.Name = "Attachment1"

				Attachment0.CFrame = v.C0
				Attachment1.CFrame = v.C1

				game:GetService("Debris"):AddItem(Attachment1, duration)

				BallSocketConstraint.Attachment0 = Attachment0
				BallSocketConstraint.Attachment1 = Attachment1

				BallSocketConstraint.LimitsEnabled = true
				BallSocketConstraint.TwistLimitsEnabled = true -- Stops snapping


			end
		end
		
		for _, v in pairs(player.Character:GetChildren()) do
			if v:IsA("Part") and v.Name ~= "Legs" and v.Name ~= "Chest" then
				v.CanCollide = true
			end
		end
		
		task.wait(duration)

		for _, v in pairs(player.Character:GetDescendants()) do
			if v:IsA("Part") and v.Name ~= "Torso" then
				print(v.Name)
				v.CanCollide = false
			end
		end

		for _, v in pairs(player.Character:GetDescendants()) do
			if v:IsA("Motor6D") then
				v.Enabled = true
			end
		end
		
		print("Set to false")
		
		player.Character:WaitForChild("Humanoid").RequiresNeck = true
		
		RagdollDebounce = false
	end

image

2 Likes