Cframe doesnt get limited from Math.Clamp

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am using CFrames on a Weld and I want to limit the angle of the Weld, so I am using Math.Clamp but it only works on one side of rotation. How would I fix this?

  1. What is the issue? Include screenshots / videos if possible!
External Media

Before Rotation

After
Screenshot 2024-11-15 175844

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I havent found anything that would fix this, thank you for any help!

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- T1 is the Turret Model, MP is the MainPart, Target is the part its looking at
	local cf = CFrame.lookAt(T1.MP.Position, Vector3.new(workspace.Target.Position.X,T1.MP.Position.Y,workspace.Target.Position.Z))
	
	local X,Y,Z = cf:ToOrientation()
	local newYAngle = math.clamp(Y, math.rad(-35), math.rad(95))

	T1.MP.Weld.C0 = T1.MP.CFrame:ToObjectSpace(CFrame.new(cf.Position) * CFrame.fromOrientation(X,newYAngle,Z))
	

I’m not an expert in CFrames, but is cf:ToOrientation() already returning a Y in radians? If not then try converting Y to radians in the math.clamp function?

For this i used math.rad for the angles that isnt the issue, the issue is that the limiter being Math.Clamp only limits the degrees if the turret is one way, i want the limiter to face all ways like equal to the body of the tank