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

How should I go about saving instances/models?

Asked by
zblox164 531 Moderation Voter
6 years ago

Note: I did sort of ask this question before but it was more focused on the placement system so I decided to ask about Data Store.

I know that you can not save instances using data store but then how do games like Theme Park Tycoon 2 and Miners Haven save the tycoon? Do I put the model or instance inside of a StringValue or IntValue then check if the value of the IntValue/StringValue is equal to a certain value then save that value? It would look a bit like this:

if game.Workspace.StringValue == "Purchased" then
    -- DataStore stuff
end

Any help appreciated! Thanks!

0
AYYYYYY MINERS HAVEN, I HAVE EXACT SAME QUESTION AS YOU, I am soooo good in mh greatneil80 2647 — 6y

1 answer

Log in to vote
1
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

one way to save instances is: you store all component models in serverstorage and then make a list of how often, where, with what rotation, etc each model occurs. Like you say you basically write a script to turn all the information you need to recreate it into text (a table with string values), then save that text (table).

This is called serialization, and you can find some scripts online and in toolbox to get you started.

Of course you also need a seconds script to do the de-serialization: reading the text and recreating your instance from it, by cloning the models from serverstorage and placing/rotating them to the right spot.

You can save custom variables (like NumberValue) with this strategy too, or really save all the baseparts and their model structure so you don't need to save anything in serverstorage and all models can be completely custom. But keep in mind that the datastore has some limits on both string/datastore size and on how often you can make calls to it, so based on how efficiently your instance can be stored, it's limited in size if you want to save it.

0
Thanks this really helped me to understand what I need to do. zblox164 531 — 6y
Ad

Answer this question