Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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!

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. EpidemioIogy 4 — 7y

1 answer

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
7 years ago

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
Much simpler and more efficent than my solution. EpidemioIogy 4 — 7y
Ad

Answer this question