Arm Replication Breaking

Hello, I am making a weapons system and I want everyone to see the arm movements. I’m sending it from the client to server then to all other clients. The issue is the one arm breaks and I cannot fix it.

Client

local RootPos = Root.Position
			local TorsoPos = Torso.Position
			local MousePos = Mouse.Hit.Position
			Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
			local rightX, rightY, rightZ = RightShoulder.C0:ToEulerAnglesYXZ()
			RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y))

			local leftX, leftY, leftZ = LeftShoulder.C0:ToEulerAnglesYXZ()
			LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-Mouse.Hit.p - -Mouse.Origin.p).unit.y))
			local DataToSend = {
				["RightData"] = {rightZ, -Mouse.Hit.p - -Mouse.Origin.p};
				["LeftData"] = {leftZ, -Mouse.Hit.p - -Mouse.Origin.p};
			}
			RepMoveEvent:FireServer("Arms", DataToSend)
			

Server

RepMoveEvent.OnServerEvent:Connect(function(plr, MovTY, data)
	if MovTY == "Lean" then
		RepMoveEvent:FireAllClients(plr.Name, "Lean", data)
	elseif MovTY == "Arms" then
		RepMoveEvent:FireAllClients(plr.Name, "Arms", data)
	end
end)

Replication Client

RepMoveEvent.OnClientEvent:Connect(function(plr, MovTY, data)
	if plr == game.Players.LocalPlayer.Name then
		return
	end
	if MovTY == "Lean" then
		--RepMoveEvent:FireAllClients(plr.Name, "Lean", data)
	elseif MovTY == "Arms" then
		print(data)
		local character = game.Players[plr].Character
		if character and character:FindFirstChild("Torso")then
			
			local Root = character:WaitForChild("HumanoidRootPart")
			local Torso = character:WaitForChild("Torso")
			local RightShoulder = Torso:WaitForChild("Right Shoulder")
			local LeftShoulder = Torso:WaitForChild("Left Shoulder")
			
			local LeftData = data.LeftData
			local RightData = data.RightData
			RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -RightData[1])) * CFrame.Angles(0, 0, math.asin((RightData[2]).unit.y))
			LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -LeftData[1])) * CFrame.Angles(0, 0, math.asin((LeftData[2]).unit.y))

		else
			print("Cannot Find Player Not Replicating")
			return
		end
	end
end)

I have no idea why that’s happening but I got it working by doing this

local RootPos = Root.Position
local TorsoPos = Torso.Position
local MousePos = Mouse.Hit.Position
Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
local rightX, rightY, rightZ = RightShoulder.C0:ToEulerAnglesYXZ()
RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y))

local leftX, leftY, leftZ = LeftShoulder.C0:ToEulerAnglesYXZ()
LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-Mouse.Hit.p - -Mouse.Origin.p).unit.y))
local DataToSend = {
		["MousePosition"] = Mouse.Hit.Position,
		["MouseOrigin"] = Mouse.Origin.Position,
	}
RepMoveEvent:FireServer("Arms", DataToSend)
RepMoveEvent.OnClientEvent:Connect(function(plr, MovTY, data)
	if plr == game.Players.LocalPlayer.Name then
		return
	end
	if MovTY == "Lean" then
		--RepMoveEvent:FireAllClients(plr.Name, "Lean", data)
	elseif MovTY == "Arms" then
		print(data)
		local character = game.Players[plr].Character
		if character and character:FindFirstChild("Torso")then

			local Root = character:WaitForChild("HumanoidRootPart")
			local Torso = character:WaitForChild("Torso")
			local RightShoulder = Torso:WaitForChild("Right Shoulder")
			local LeftShoulder = Torso:WaitForChild("Left Shoulder")

			local MousePosition = data.MousePosition
			local MouseOrigin = data.MouseOrigin
			
			local rightX, rightY, rightZ = RightShoulder.C0:ToEulerAnglesYXZ()
			local leftX, leftY, leftZ = LeftShoulder.C0:ToEulerAnglesYXZ()

			LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-MousePosition - -MouseOrigin).unit.y))
			RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((MousePosition - MouseOrigin).unit.y))
		else
			print("Cannot Find Player Not Replicating")
			return
		end
	end
end)

More debugging

Client Side

local RootPos = Root.Position
local TorsoPos = Torso.Position
local MousePos = Mouse.Hit.Position
Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))

local rightX, rightY, rightZ = RightShoulder.C0:ToEulerAnglesYXZ()
RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y))

local leftX, leftY, leftZ = LeftShoulder.C0:ToEulerAnglesYXZ()
LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y))

local DataToSend = {
    ["RightData"] = {rightZ, Mouse.Hit.p - Mouse.Origin.p};
    ["LeftData"] = {leftZ, Mouse.Hit.p - Mouse.Origin.p};
}
RepMoveEvent:FireServer("Arms", DataToSend)

Server Side

RepMoveEvent.OnServerEvent:Connect(function(plr, MovTY, data)
    if MovTY == "Arms" then
        RepMoveEvent:FireAllClients(plr.Name, "Arms", data)
    end
end)

Replication Client Side

RepMoveEvent.OnClientEvent:Connect(function(plr, MovTY, data)
    if plr == game.Players.LocalPlayer.Name then
        return
    end
    if MovTY == "Arms" then
        print("Data received for arms:", data)
        local character = game.Players[plr].Character
        if character and character:FindFirstChild("Torso") then
            local Root = character:WaitForChild("HumanoidRootPart")
            local Torso = character:WaitForChild("Torso")
            local RightShoulder = Torso:WaitForChild("Right Shoulder")
            local LeftShoulder = Torso:WaitForChild("Left Shoulder")
            
            local LeftData = data.LeftData
            local RightData = data.RightData
            
            -- Debugging values
            print("Right Shoulder Data:", RightData)
            print("Left Shoulder Data:", LeftData)
            
            RightShoulder.C0 = (RightShoulder.C0 * CFrame.Angles(0, 0, -RightData[1])) * CFrame.Angles(0, 0, math.asin((RightData[2]).unit.y))
            LeftShoulder.C0 = (LeftShoulder.C0 * CFrame.Angles(0, 0, -LeftData[1])) * CFrame.Angles(0, 0, math.asin((LeftData[2]).unit.y))
        else
            print("Cannot find player, not replicating")
        end
    end
end)