Im trying to create a compass, like the pubg or skyrim one for my rpg game, except im trying to use the camera's rotation cframe and its not working?

local x,y,z = cam.CFrame:toEulerAnglesXYZ()
local angle = math.deg(z)
print(angle)

it prints the correct angles north east south west, except all the inbetween angles are really close to eachother, so it jumps from north to east suddenly.