How can I save a CFrame in a data store?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am attempting to store where a player spawned (the spawn box position their in) and then add it back to a table when they press play or disconnect from the server.

  1. What is the issue? Include screenshots / videos if possible!

I am simply asking if anyone has ideas for how to efficiently store CFrame values in data stores. I found an example below, but it was a bit confusing to understand. If anyone could help me with this It’d be greatly appreciated!

:smiley: cheers!

^Article that had a solution, but I cannot understand.

2 Likes

You could serialize it

local cframe = {CFrame:GetComponents()}
2 Likes

CFrames cannot be serialized (converting data into a format that can be saved/transferred around/etc) to JSON, so you’ll have to do the serializing yourself. One way of doing this is getting the components and saving them all into an array using cf:GetComponents

local serialized = { cf:GetComponents() }
-- then save

-- to load
local deserialized = CFrame.new(table.unpack(serialized))
23 Likes

Thanks for the help and, to be clear, would I save “Serialized” to my datastore?

Yes, and deserialized would be the actual CFrame that was saved

1 Like