I’m trying to get what would be x, y, and z orientation values from a CFrame, using the “convert” function. I used the code to point a part towards another one, then compare what I got from “convert” to the actual part’s orientation. The x and y values seem to be fine, but it looks like z is nonsense.

Sometimes z would print as 0, as it should, but sometimes z would print as “9.6435354297272e-07” or something similar.

It also seems a little . . inaccurate . .
I have no idea what else to do.

convert = function(cf)
local x, y, z = cf:ToOrientation()
x = x * (180 / math.pi)
y = y * (180 / math.pi)
z = z * (180 / math.pi)
return x, y, z
end
lookat = CFrame.new(workspace.fora.Position, workspace.at.Position)
x, y, z = convert(lookat)
workspace.fora.CFrame = lookat
print(x, y, z)

I think you’re making this a bit complicated lol
I’m not sure if this will work but to get the rotational values you can do:

local newCFrame = CFrame.new(workspace.fora.Position, workspace.at.Position)
local x, y, z = newCFrame:ToOrientation()
workspace.fora.CFrame = newCFrame
print(x, y, z)

The developer hub does mention that CFrame:ToOrientation() returns approxmiate angles to regenerate the CFrame, but 9.6435354297272e-07 is a really small number – this is in scientific / index notation to represent 0.00000096435354297272

An alternative is by using some trigonometric functions:

local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = CFrame:GetComponents()
local X = math.atan2(-m12, m22)
local Y = math.asin(m02)
local Z = math.atan2(-m01, m00)

You of course have to convert it to degrees because all trigonometric functions in the math library use and / or return radians by using math.deg or the same math you used to convert it