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.
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.
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.