It looks like gimbal lock, which happens when you rotate a CFrame by 90 degrees. Basically the Axes of 2 of the rotations end up in the same place and affect each other.
Try typing “gimbal lock” into the search tool up top to see if those posts can help you out.
I merely skimmed this thread but if you’re having the same issue I was, I think that I was able to resolve it.
I’ll take a look at my code and report back (if i remember lol). In the meantime, check out AxisAngles’s twitter, he posts useful tricks like how to overcome stuff like this
This post explains how roblox handles adding and subtracting orientations. The errors seemed to be lines:
local _, rY2 = Camera.CFrame:ToOrientation()
local freelookLowLimit = math.floor(math.deg(rY2)-60)+0.001
local freelookHighLimit = math.floor(math.deg(rY2)+60)+0.001
I fixed this by using:
local ChangeCFrame = PreviousCameraCFrame.Rotation:ToObjectSpace(Camera.CFrame.Rotation)
and manually checking the Y degrees if it exceeded it.
local _, Y, _ = ChangeCFrame:ToOrientation()
if Y > 60 then
-- Set to 60
elseif Y < -60 then
-- Set to -60
end
If it did exceed it, I would manually set the Y orientation of the camera to whatever it was clamped to.