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

How do you save models in a datastore?

Asked by 5 years ago

For example, in Miner's Haven you can place models and if you leave and come back they load up in the same position.

How does one do that?

I looked up another article and they talked about serialization, but can someone explain in-depth what that is and provide some links or example code on it?

1
You cannot save objects, basicly save all the properties, how you do that is your choice User#20388 0 — 5y
0
i can type up a script give me like an hour or so mattchew1010 396 — 5y
0
actually thats really hard to do mabe i can try later but not now mattchew1010 396 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

In the Roblox Datastore, you can only save datatypes such as Integers, Numbers, Strings, Booleans, and Tables.

If you don't know what these are go here: http://wiki.roblox.com/index.php?title=Data_types

In order to save a model, you would likely want it's position, rotation, and what it is. All the extra attributes such as customization can also be saved, but those are the main three.

For each model in your game you should have a PrimaryPart, this is not required, but makes it much easier. Therefore if you do have a PrimaryPart, you would save the following:

local pos = tostring(Model.PrimaryPart.Position) -- Can't save the position since it is a Vector3 value
local rot = tostring(Model.PrimaryPart.Orientation) -- Same here, Vector3 value
local Type = Model.Name

You can insert all of these into a table and attach it to the player's key in the datastore.

So when you load it, you would get the type of model saved, and clone it from a storage place. You would then do setPrimaryPartCFrame and set the position and rotation.

Ad

Answer this question