Saving a CFrame to a Datastore efficiently

Hey, I’ve been working on a project with a placement system. All the data saves perfectly, and the entire system is basically done. But the thing Is I have no idea how to convert a CFrame into a table.

BEFORE you reply to this post to a link to: DataStore and CFrame storing I’ve already looked over this and read it, even using the functions given and they didn’t work.

If anyone has any ideas, please give them. Thanks! :slight_smile:

1 Like

a CFrame is basically position and rotation, you can split it into position and rotation, then split each of these into 6 numbers. Organize these numbers however you like and save them.

1 Like

wait, what do you mean they didn’t work? was there any errors? what happened?
Having looked at the code in the post, looks like it should’ve worked?

1 Like

It was turning into a single value, and not a table. But the single value was “1.07” not enough info for a CFrame

I assume you used something like this?

local data = {yourCFrame:components()}

local yourCFrame = CFrame.new(unpack(data))

If that’s the case, it sounds like you just forgot {}
But of course I don’t have the code so I couldn’t say for sure.

3 Likes

YES! IT WORKS, THANK YOU SOOO MUCH.

you saved my life

If anyone else has this problem make sure to use {}

2 Likes

Glad to hear it! Just FYI, some functions return multiple values and this is one of them. If you wanted to get all of the data without {}, it looks like this.

local x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22 = yourCFrame:components()

So in your case, the single number was the X position since you only set one variable.

1 Like

Although this has already been answered, if you want to improve the efficiency of saved CFrame’s (namely reducing the 12 floating point numbers into just 7), you can convert the CFrame’s into Quaternions.

Just an added thing I thought you might consider to improve your serialization.

2 Likes