Help Saving CFrame.Angles

Hello,

I am working on a game that has a placement system. Due to each spot being a one to three-digit number, I do not need to save the XYZ values of the CFrame value; I only need to save the CFrame.Angles part of it. Unfortunately, no matter what I try, it doesn’t want to save the correct values. Here is the code I am having the most trouble with:

local pTycoon = tycoons[player.PlayerData.CurrentTycoon.Value]
local function saveItemData(folder)
	for _, spot in pairs(folder:GetChildren()) do
		player.PlayerData.Spots[spot.itemStats.itemSpot.Value].Item.Value = spot.Name
		print(string.format("WHY GOD WHY | %s, %s, %s", spot.Model.baseplate.CFrame:ToEulerAnglesXYZ())) -- I got very frustrated yesterday with this lol
		player.PlayerData.Spots[spot.itemStats.itemSpot.Value].Orientation.Value = CFrame.Angles(spot.Model.baseplate.CFrame:ToEulerAnglesXYZ())
	end
end
for _, folder in pairs(pTycoon.playerStructures:GetChildren()) do
	saveItemData(folder)
end

And here is what is being printed from that function:

Now obviously, this is completely wrong. The first and last coordinate should always be zero while the middle one should be a 0-360 as I only allow for 90-degree rotations. This isn’t a problem with my placement system as when I go through each structure’s orientation manually, they are exactly within the bounds that I defined earlier. I even tried manually modifying the code to get it to work in the command bar, and it worked how I wanted it to.

Does anyone know what I might be doing wrong?

Thanks,
— Ham

The only value that’s incorrect is the first one but it’s like such a small inaccuracy that you could resolve it by rounding the value.

I guess I should have clarified: they should also be divisible by 90 or be zero. It telling me those values completely baffles me as that’s not even close to the actual rotation values of those items.

You need to convert the values from radians to degrees…

That still doesn’t explain the first value not being zero.

Here is an example of one structure: It’s orientation is 0, -90, 0. For whatever reason, it is printing this:

tostring(CFrame.Angles(spot.Model.baseplate.CFrame:ToEulerAnglesXYZ()))

Is there any reason you can’t round values? I’m wondering if it’s just an issue with how Euler angles are calculated and is something that is unavoidable.

Well, the issue is that the orientation that I want to save is 0, -90, 0 yet the orientation I am getting back from :ToEulerAnglesXYZ is 0, 0, 0. Rounding does not solve this issue.

What are the other numbers being printed for? I’m trying to replicate the issue in my studio right now.

Are the parts you getting orientation of grouped models?

I just realized that I was doing it on a part instead of a model. No wonder I got so frustrated last night lol. Sorry for the inconvenience.

1 Like

No worries, glad you got it figured out.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.