Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I save and load a model's CFrame?

Is there a way to save and load a model's CFrame (position and rotation) using DataStore or some other way to save and load data after a player has joined/left? Something like Miners Haven where it saves everything on your base and loads it when you join.

I just need to know if using DataStore is the correct method in doing so, and if so, I'd like to know a brief guideline on how I should go about using DataStore to store the CFrame values to prevent DataStore from being overloaded.

Any guidance will be greatly appreciated!

1 comment

0

There is not a DataStore method for doing so, but Stravant's BitBuffer module has a method called WriteRotation and ReadRotation which can convert the value into a string that can be saved into the data store.

1 answer

✓ Accepted answer

To save something like CFrame in data store you simply save a table of its values, then unpack the table later. Rough example:

local cf = CFrame.new()
local tab = { cf:components() } --components is a tuple of values
datastore:SetAsync('key',tab)
--later
local tab = datastore:GetAsync('key')
local cf = CFrame.new(unpack(tab))

1 comment

1

Much simpler and more efficent than my solution.

This discussion is preserved as it was. New answers, comments, and votes are closed.