Player breaks their neck after flicking their camera too much or just randomly when joining

I’m trying to make a head movement system, it’s working amazing but sometimes the neck joint somehow weirdly starts rotating or something? It does look funny. But its not very great to have.

Code: (only important part)

script.CameraPos.OnServerEvent:Connect(function(plr,cf,block)
	local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:GetComponents()

	local X = math.atan2(-m12, m22)

	local Y = math.asin(m02)

	local Z = math.atan2(-m01, m00)

	attachment.WorldCFrame = CFrame.Angles(X,Y,Z)

	local rotationcframe = attachment.CFrame.Rotation

	local fullcframe = rotationcframe + neck.C0.Position

	ts:Create(neck,tsinfo,{C0 = fullcframe}):Play()
end)

This code sets the rotation of the neck joint to the rotation of the camera btw.

Video of what happens:

Thanks for reading.

he issue comes from directly setting the neck joint’s c0 to the fullcframe. this can cause weird behavior because c0 is the offset of the joint and manipulating it directly can result in strange rotations.

preserve the neck’s position while adjusting only its rotation. this ensures that the neck joint stays in the correct position and only the rotation is changed.

use euler angles to apply the rotation from the camera. by using cframe.fromeuleranglesxyz the rotation becomes more predictable and avoids complex rotational issues.

combine the neck’s current position with the new rotation. instead of directly setting c0 to the camera’s full cframe combine the neck’s position with the camera’s rotation to maintain a stable joint position.

optionally use tweenservice to smoothly transition the neck’s rotation, creating less jerky movement.

these changes should help with the problem and the weird rotation. hope this helps tell me if you need more help