Ragdoll not working all of the time

Hi, I’m always getting this warning:

The ragdoll doesn’t fall to the ground if that error occurs. Here’s my code:

	local function ConnectLimbs(char)
		for i, limb in pairs(char:GetChildren()) do
			if limb:IsA("BasePart") then
				local atch0, atch1, atch2, atch3, atch4, atch5

				if limb.Name == "Head" then
					limb.CanCollide = true
					atch0 = char.Head.NeckRigAttachment
					atch1 = char.UpperTorso.NeckRigAttachment
				elseif limb.Name == "UpperTorso" then
					limb.CanCollide = true
					atch0 = char.UpperTorso.WaistRigAttachment
					atch1 = char.LowerTorso.WaistRigAttachment

					atch2 = char.UpperTorso.LeftShoulderRigAttachment
					atch3 = char.LeftUpperArm.LeftShoulderRigAttachment

					atch4 = char.UpperTorso.RightShoulderRigAttachment
					atch5 = char.RightUpperArm.RightShoulderRigAttachment
				elseif limb.Name == "LowerTorso" then
					limb.CanCollide = true
					atch0 = char.LowerTorso.LeftHipRigAttachment
					atch1 = char.LeftUpperLeg.LeftHipRigAttachment

					atch2 = char.LowerTorso.RightHipRigAttachment
					atch3 = char.RightUpperLeg.RightHipRigAttachment
				elseif limb.Name == "LeftUpperLeg" then
					limb.CanCollide = true

					atch0 = char.LeftUpperLeg.LeftKneeRigAttachment
					atch1 = char.LeftLowerLeg.LeftKneeRigAttachment
				elseif limb.Name == "RightUpperLeg" then
					limb.CanCollide = true

					atch0 = char.RightUpperLeg.RightKneeRigAttachment
					atch1 = char.RightLowerLeg.RightKneeRigAttachment
				elseif limb.Name == "LeftLowerLeg" then
					limb.CanCollide = true

					atch0 = char.LeftLowerLeg.LeftAnkleRigAttachment
					atch1 = char.LeftFoot.LeftAnkleRigAttachment
				elseif limb.Name == "RightLowerLeg" then
					limb.CanCollide = true

					atch0 = char.RightLowerLeg.RightAnkleRigAttachment
					atch1 = char.RightFoot.RightAnkleRigAttachment
				elseif limb.Name == "LeftUpperArm" then
					limb.CanCollide = true

					atch0 = char.LeftUpperArm.LeftElbowRigAttachment
					atch1 = char.LeftLowerArm.LeftElbowRigAttachment
				elseif limb.Name == "RightUpperArm" then
					limb.CanCollide = true

					atch0 = char.RightUpperArm.RightElbowRigAttachment
					atch1 = char.RightLowerArm.RightElbowRigAttachment
				elseif limb.Name == "LeftLowerArm" then
					limb.CanCollide = true

					atch0 = char.LeftLowerArm.LeftWristRigAttachment
					atch1 = char.LeftHand.LeftWristRigAttachment
				elseif limb.Name == "RightLowerArm" then
					limb.CanCollide = true

					atch0 = char.RightLowerArm.RightWristRigAttachment
					atch1 = char.RightHand.RightWristRigAttachment
				end

				if atch0 and atch1 then
					local ballInSocket = Instance.new("BallSocketConstraint", limb)
					ballInSocket.Attachment0 = atch0
					ballInSocket.Attachment1 = atch1
				end

				if atch2 and atch3 then
					local ballInSocket = Instance.new("BallSocketConstraint", limb)
					ballInSocket.Attachment0 = atch2
					ballInSocket.Attachment1 = atch3
				end

				if atch4 and atch5 then
					local ballInSocket = Instance.new("BallSocketConstraint", limb)
					ballInSocket.Attachment0 = atch4
					ballInSocket.Attachment1 = atch5
				end

			elseif limb:IsA("Accessory") then
				local h = limb:FindFirstChild("Handle")
				if h then
					local part0 = char.Head
					local atch = h:FindFirstChildOfClass("Attachment")

					if atch.Name == "HatAttachment" or atch.Name == "FaceFrontAttachment" then
						part0 = char.Head
					end

					local ap = Instance.new("AlignPosition", part0)
					if part0 == char.Head then
						ap.Attachment1 = char.Head:FindFirstChild(atch.Name)
						ap.Attachment0 = atch
						ap.RigidityEnabled = true
						ap.Responsiveness = 200
					end

					local ao = Instance.new("AlignOrientation", part0)
					if part0 == char.Head then
						ao.Attachment1 = char.Head:FindFirstChild(atch.Name)
						ao.Attachment0 = atch
						ao.RigidityEnabled = true
						ao.Responsiveness = 200
					end
				end
			end
		end
	end

character:WaitForChild("Humanoid").Died:Connect(function()			
			if game.ReplicatedStorage.Values.GameInProgress.Value == true then
					ConnectLimbs(character)
					local test = (character:GetChildren())

					local testing = Instance.new("Model",game.Workspace:FindFirstChild("Map"))
					for i = 1, #test do
						local child = test[i]
						child:Clone()
						child.Parent = testing
					end
				end
			end