How would I limit how far the camera can follow a player's mouse?

I am currently working on a menu for my game and the camera follows the mouse and moves 360 degrees around the location of it.


Is there a way to limit how far it can follow?

Code:

You can convert the end goal to orientation using CFrame:ToOrientation() get the XYz angles, convert them to degrees, use math.clamp on the angles, convert to radians, then reconstruct the CFrame using CFrame.fromOrientation(x,y,z).

A neat property with CFrame look at is there is no roll in the Z axis so it’s basically 0 usually unless you change the up vector of CFrame.lookat.