Client Sided Ragdoll Completely Messes up!

Hey there, I’m trying to make a client-sided ragdoll. But it only works sometimes and sometimes it doesn’t work.

Server:

local RagdollEvent = game.ReplicatedStorage.RagdollState
local DefaultWalkSpeed = 16

local Velocity = 25

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		
		Character.Humanoid.BreakJointsOnDeath = false
		Character.Humanoid.RequiresNeck = false
		Character.HumanoidRootPart.Massless = true
		Character.Archivable = true
		local isRagdoll = Instance.new("BoolValue")
		isRagdoll.Parent = Character
		isRagdoll.Name = "isRagdoll"
		
		isRagdoll.Changed:Connect(function(value : boolean)
			if value then
				local Humanoid : Humanoid = Character:WaitForChild("Humanoid")
				Humanoid.WalkSpeed = 0
				
				for _, v in Character:GetDescendants() do
					if v:IsA("BasePart") then
						v:SetNetworkOwner(Player)
					end
				end
			
				Humanoid.JumpPower = 0
				Humanoid.AutoRotate = false 
			
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding, true)
			else
				Character:WaitForChild("Humanoid").WalkSpeed = DefaultWalkSpeed
				Character.Humanoid.JumpPower = 50
			end
			RagdollEvent:FireAllClients(Character, value)
		end)
		
		Character.Humanoid.Died:Connect(function()
			isRagdoll.Value = true
			wait(game.Players.RespawnTime)
			isRagdoll.Value = false
		end)
	end)
end)

game.ReplicatedStorage.ToggleRagdoll.OnServerEvent:Connect(function(Player)
	local Character = Player.Character
	Character.isRagdoll.Value = not Character.isRagdoll.Value
end)

Client:

local RagdollEvent = game.ReplicatedStorage.RagdollState


local attachmentCFrames = {
	["Neck"] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
	["Left Shoulder"] = {CFrame.new(-1.3, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1), CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)},
	["Right Shoulder"] = {CFrame.new(1.3, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)},
	["Left Hip"] = {CFrame.new(-0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
	["Right Hip"] = {CFrame.new(0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
}

local ragdollInstanceNames = {
	["RagdollAttachment"] = true,
	["RagdollConstraint"] = true,
	["ColliderPart"] = true,
}



RagdollEvent.OnClientEvent:Connect(function(Character, Value : boolean)
	local Humanoid = Character:WaitForChild("Humanoid")
	if Value then 
		
		local function createColliderPart(part: BasePart)
			if not part then return end
			local rp = Instance.new("Part")
			rp.Name = "ColliderPart"
			rp.Size = part.Size/1.7
			rp.Massless = true			
			rp.CFrame = part.CFrame
			rp.Transparency = 1

			local wc = Instance.new("WeldConstraint")
			wc.Part0 = rp
			wc.Part1 = part

			wc.Parent = rp
			rp.Parent = part
		end
		local function replaceJoints()
			local success, err = pcall(function()
			for _, motor in pairs(Character:GetDescendants()) do
				if motor:IsA("Motor6D") then
					if not attachmentCFrames[motor.Name] then return end
					motor.Enabled = false;
					local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
					a0.CFrame = attachmentCFrames[motor.Name][1]
					a1.CFrame = attachmentCFrames[motor.Name][2]

					a0.Name = "RagdollAttachment"
					a1.Name = "RagdollAttachment"

					createColliderPart(motor.Part1)

					local b = Instance.new("BallSocketConstraint")
					b.Attachment0 = a0
					b.Attachment1 = a1
					b.Name = "RagdollConstraint"

					b.Radius = 0.15
					b.LimitsEnabled = true
					b.TwistLimitsEnabled = false
					b.MaxFrictionTorque = 0
					b.Restitution = 0
					b.UpperAngle = 90
					b.TwistLowerAngle = -45
					b.TwistUpperAngle = 45

					if motor.Name == "Neck" then
						b.TwistLimitsEnabled = true
						b.UpperAngle = 45
						b.TwistLowerAngle = -70
						b.TwistUpperAngle = 70
					end

					a0.Parent = motor.Part0
					a1.Parent = motor.Part1
					b.Parent = motor.Parent
				end
			end
			end)
			if success then
				print("Success")
			else
				warn("Failed!! " .. err)
			end
			end	
			

		replaceJoints()
		Character.Torso:ApplyImpulse(Character.Torso.CFrame.LookVector * 1000) -- Test
		
	else
		local function resetJoints()
			if Humanoid.Health < 1 then return end
			for _, instance in pairs(Character:GetDescendants()) do
				if ragdollInstanceNames[instance.Name] then
					instance:Destroy()
				end

				if instance:IsA("Motor6D") then
					instance.Enabled = true;
				end
			end

			Humanoid.AutoRotate = true
		end
		
		resetJoints()
	end
end)