How to work with rotation and CFrame?

Hello,

I’m working on a DataStore which can save builds / furniture. My method is to save:

  • Model Name.
  • X, Y, Z of Primary Part
  • Rotation of primary part.
    X, Y, Z is easy to fetch, but for rotation I do this:
-- This is the only axis rotation can be done on.
local Rotation = CFrame.Angles(0, 0, 0) -- At start of placement session.
-- Rotation *= CFrame.Angles(0, math.rad(90), 0) -- On each rotation step.
local _, y = Rotation:ToOrientation()

Then I reapply like this:

local newModelCFrame = Kellogs.KellogToCFrame(v.CFrame) -- Forms a CFrame from an X,Y,Z (Basically, there's more to it)
local newModelRotation = v.Rotation.Value -- The previously saved "y" from above extract.
					
newModelCFrame *= CFrame.Angles(0, newModelRotation, 0)

newModel:SetPrimaryPartCFrame(newModelCFrame)

The models always end up crooked / askew, which looks weird when the models rotate at 90 degrees intervals.

Am I doing something wrong / missing something?

I would print all related data. Make a blank CFrame using the positional vectors, and then multiply by a CFrame.Angles. You could also have an issue with the Pivot of the primary part.

Resolved, in case anyone else needs it:

Serialise the entire CFrame of the primary part using this:

--> You get the message.. extract what you need
CoreFunctions.TranslateDataToSession = {
	["userdata"] = function(x)
		x = CFrame.new(table.unpack(x));
		print(x)
		return x
	end,
}

CoreFunctions.TranslateSessionToData = {
	["userdata"] = function(x)
		x = {x:GetComponents()}
		print(x)
		return x
	end,
}