Recently, I was working on a script that locks the rotation of a camera while keeping the position the same. While working on that, I noticed something odd: My output changes simply by storing a ToEulerAnglesXYZ value a variable:
print(CFrame.new():ToEulerAnglesXYZ()) local a=CFrame.new():ToEulerAnglesXYZ() print(a) Output: -0, 0, -0 ;
-0`
Note that by assigning a variable, for some reason the value changes. type(CFrame.new():ToEulerAnglesXYZ()) and local a=CFrame.new():ToEulerAnglesXYZ() print(type(a)) both output number. However, because of this little change from (-0, 0, -0) to (-0) when assigning ToEulerAnglesXYZ() to a variable I get an error when working with some CFrames
Full code: local cam=workspace.CurrentCamera lastcamrot=cam.CFrame:ToEulerAnglesXYZ() cam.CFrame=CFrame.new(cam.CFrame.Position)*CFrame.Angles(lastcamrot)
–>error
Meanawhile, this works, though I can’t use it for what i’m trying to do: local cam=workspace.CurrentCamera cam.CFrame=CFrame.new(cam.CFrame.Position)*CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ())
I don’t think this is a bug I think it is just the behavior of the way it prints. try printing a:GetComponents() and CFrame.new():ToEulerAnglesXYZ():GetComponents() they should return the same value.
The issue is that the function returns three numbers which is a lua thing but it’s being stored in only one variable so you only get the X component of the euler angles. Consequently, we need to create three variables to assign those three numbers that are being returned like so:
Also use ``` to format your code next time
local lastX,lastY,lastZ =cam.CFrame:ToEulerAnglesXYZ()
cam.CFrame=CFrame.new(cam.CFrame.Position)*CFrame.Angles(lastX,lastY,lastZ)
Doing this doesn’t make a difference, regardless of where the getcomponents is put. I also noticed that in the watch window, only a single number is shown.