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

Is saving instances using data store how tycoons like Miners Haven save their players progress?

Asked by
zblox164 531 Moderation Voter
6 years ago

So I asked a while back how to save instances and got a very detailed reply by Nonaz_jr about the process. Here is what he said:

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.

So for saving worlds like on a tycoon do you use this for every object or something completely different? For instance games like miners haven have a saving system where it saves the cash (I know how to save leaderstats) but also the game progress so you don't loose everything you accomplished. I don't have any code because I don't know where to start.

Again thanks for Nonaz_jr for helping me get a start to this topic. Thanks for all who help!

The reason I ask this for the third time is because it is a large topic.

0
It isn't really a 'large topic' if you know how datastores work this is very easy to do User#20388 0 — 6y
0
Save in a DataStore - PartName, Position, Color, Size, etc... Then create the part when it loads. i.e. ServerStorage:WaitForChild("Part_Needed"):Clone() then set properties. MooMooThalahlah 421 — 6y
0
Thanks this is what I thought I had to do just wanted to confirm. zblox164 531 — 6y
0
Also I was not sure if what I was doing was correct zblox164 531 — 6y

1 answer

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

Hi, I came across this, so I will shortly adress some last things you come across with this approach.

To save the location of your models, make sure they have a PrimaryPart, then save the CFrame using model.PrimaryPart.CFrame:components() and put that value in a table.

You can store numbers, strings and booleans in the datastores (not CFrames or objects etc). Any properties of the model that you want to save, manually put it in your table in one of those three formats (this is called serialization). Then save that table.

Then to load the game from your save file, just get the saved CFrame values and do: CFrame.new(unpack(savedCFrameValues))

Clone your model from serverstorage, set it's CFrame to the loaded CFrame using SetPrimaryPartCFrame(), apply any other properties that you saved manually, then parent the clone to workspace (or something in workspace).

Hope you already got it working, then maybe it helps anyone else still. Good luck with your game!

0
Could I use GetPrimaryPartCFrame() for getting the location? zblox164 531 — 6y
0
Also thanks! zblox164 531 — 6y
Ad

Answer this question