How would you guys save models orientation with data store?

so my current method is to save models hitbox orientation, then load it, and then convert it into CFrame.Angles() with radians, but this method is glitchy, because it sometimes reverts the rotation, so i’d like to know, if you have any different methods for that

Why not just save the CFrame? CFrame has an orientation parameter

im pretty sure you cannot save cframes in data store right

I meant saving the data in the CFrame

i dont think there is an orientation parameter

image

https://developer.roblox.com/en-us/api-reference/datatype/CFrame

This post does a good job explaining the idea of serializing parts or models and giving them an identity that CAN be saved.

You can’t directly save CFrame values, but you can turn the CFrame into certain values such as:

Position X - Number Value
Position Y - Number Value
Position Z - Number Value

Orientation X - Number Value
Orientation Y - Number Value
Orientation Z - Number Value

This situation chops up all of the data that makes up a CFrame and serializes it into a way that can be saved with DatastoreService

If you know how you encoded or serialized your data, you can DEserialize it, or turn it back into what it previously was, in this case, a CFrame value. The method I broke down was saving each individual axis vector3, so DEserializing would take those individual values and put them together.

It could look something like this:

CFrame.new(Vector3.new(Position X, Position Y, Position Z), Vector3.new(Orientation X, Orientation Y, Orientation Z))

or something along the lines.

There are many algorithms for serializing/deserializing data. There is no right way to handle this.

CFrame:GetComponents works wonders, and to reconstruct it, all you have to do is

CFrame.new(unpack(ComponentsTable))

ComponentsTable is whatever table you store the components.