CFrame angles behaving differently based on the camera direction?

Heya,
I got a tiny problem. I was making an SCP: Containment Breach inspired camera system, where the camera sways from left to right and remains on the same angle once you stop walking. It works well until I look to a different direction and the “saved angle” seems to be very off. Here’s a video to get what I mean, since I know I could’ve explained it better.


See how the camera snaps when I walk the other direction? Yeah, that’s the issue.

And here’s the code:

local char_lastPos = nil
local cam_LastCamRad = 0
local sine = nil
local currentTime = .012

rn.RenderStepped:Connect(function()
	if char and human.Health > 0 then
		if char_lastPos ~= nil then
			if (char_lastPos - root.Position).Magnitude > .1 then -- While Walking				
				currentTime = currentTime +.012

				sine = math.sin( currentTime *10 ) / 60
				cam.CFrame = cam.CFrame * CFrame.Angles(0,0, sine)

				local x,y,z = cam.CFrame:ToEulerAnglesXYZ()
				cam_LastCamRad = z

			elseif (char_lastPos - root.Position).Magnitude < .1 then  -- While Standing Still
				cam.CFrame = cam.CFrame * CFrame.Angles(0,0,math.clamp(cam_LastCamRad,-.009, .009))
			end
		end
		char_lastPos = root.Position
	end
end)

It’s safe to say I am pretty bad with CFrames, so any sort of help would be much appreciated!

Alright!
A few painful hours later and I present the simplest solution:

I changed the cam_LastCamRad to sine, therefore not referring to angles of the camera, but rather the sine wave.