Weird issue with saving part orientations

I have a persistent building game. Sometimes, (seemingly when an object is rotated at odd angles), their data for their orientation gets messed up, and when you load it back in it turns out something like this (this should be a straight sloped rooftop, and it was built as such):

I am not sure why this is happening and I can only get it to replicate sometimes, so I am going to drop my code here to see if anyone can point me in the right direction.

--Saving The Data
table.insert(data, {
	building.Name,
	building.PrimaryPart.CFrame.Position.X,
	building.PrimaryPart.CFrame.Position.Y,
	building.PrimaryPart.CFrame.Position.Z,
	building.PrimaryPart.Orientation.X,
	building.PrimaryPart.Orientation.Y,
	building.PrimaryPart.Orientation.Z,
	building:FindFirstChild("PartsListGui").Data.Owner.Value,
	building:FindFirstChild("PartsListGui").Data.CurrentlyBuilding.Value,
	building:FindFirstChild("PartsListGui").Data.AllMaterials.Value
})
end

--Loading
newBuilding:PivotTo(CFrame.new(obj[2], obj[3], obj[4]) * CFrame.Angles(obj[5]*math.pi/180, obj[6]*math.pi/180, obj[7]*math.pi/180))

Any thoughts why this is happening? It’s seemingly occurring for objects rotated on two axes or more, but I can’t be completely certain what’s causing it and cannot get it to reliably replicate.

1 Like
1 Like

Not sure I understand. I should put the Y value first, instead of X? Or use CFrame.fromOrientation()?