Issues with camera rotation

Hi there,
I’m using Quenty’s spring module to make a spring-based camera system however I’ve run into an issue when the character rotates 180 degrees - rather than the camera smoothly turning from a rotation of 180 degrees to 181 degrees, the camera will instead reach that angle by travelling along the rotation axis in the other direction as you can see by this video:

I think this is caused by the fact the spring module lerps between to values, and you can’t lerp with any values past 180 degrees as beyond that the angle values are negative (like -pi).

Is there anyway to workaround this (i.e. get the module to transition between negative and positive rotations)?

Here’s the code:
(P.S. sorry for poor formatting haven’t used this forum for a long time lol)

	local positionSpring =
	local anglesSpring =

	positionSpring.Damper = 0.6
	positionSpring.Speed = 2

	local function CFrameToVector3(cframe: CFrame)
		local position = cframe.Position
		local angles =

		return position, angles

	local function Vector3toCFrame(vector3: Vector3, angles)
		local newCFrame = CFrame.fromEulerAnglesYXZ(angles.X, angles.Y, angles.Z)
		newCFrame = * newCFrame

		return newCFrame

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable


	connObj = RunService.Heartbeat:Connect(function()
			local targetCFrame = rootPart.CFrame *, d.y, d.z)
			local position, angles = CFrameToVector3(targetCFrame)

			angles.Target = angles
			positionSpring.Target = position

			local newSpringPosition = positionSpring.Position
			local newSpringAngles = anglesSpring.Position

			workspace.CurrentCamera.CFrame = Vector3toCFrame(newSpringPosition, newSpringAngles)


Can you just calculate with if angles.X > 180 then angles.X = -1 * (180 - (180 - angles.X))
Someone else probably knows a much cleaner way to calculate that.

Either that or use math.clamp to make sure the value never goes above 180 or below -180.