Help With Camera Script

I’m trying to make a first-person camera completely from scratch, for learning purposes, but I’m getting this “error”:

the camera moves in the direction of my mouse, but it always returns to the “center”


	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	local camDeltaX = userInputService:GetMouseDelta().X
	local camDeltaY = userInputService:GetMouseDelta().Y
	local newY = -(camera.CFrame.Rotation.X + camDeltaX) * deltaTime * camSensX
	local newX = -(camera.CFrame.Rotation.Y + camDeltaY) * deltaTime * camSensY
	camera.CFrame = * CFrame.Angles(newX, newY, 0) 

You’re using CFrame.Rotation which doesn’t get the actually return the rotation that you expect
You should be using CFrame:ToOrientation()

local a = math.rad(90)
local cf = CFrame.Angles(a, a, a).Rotation
print(cf.X, cf.Y, cf.Z) --> 0 0 0

local deg = math.deg
local cf =, a, a):ToOrientation())
local x, y, z = CFrame.Angles(a, a, a):ToOrientation() -- optionally you can do this if you like it better

print(deg(cf.X), deg(cf.Y), deg(cf.Z)) --> 0 90 -180 (this is correct even though we set it all to 90)

Now i think it’s ToOrientation that is the correct one, however if you start to notice that it doesn’t orient properly when going 360 degrees, try using ToEulerAnglesXYZ but I think ToOrientation is correct