Datastore2 questions

I am going to be using Datastore2 for my game, but I have some questions beforehand.

I have quite a lot of data that I want to store, e.g. Cash, Bank, Kills, deaths, tools, and then other data such as total money spent, and its goes on.

Q1 The best way to sort the data: the best way I see this is to have it all stored in one table, so that it is easy to access and change, but I could be wrong.

Q2 is it possible to access data from the past? I’m thinking long-term, and what if something went really bad and I wanted to revert everyone’s data from days before.

Q3 what is the best way to handle update requests from different scripts? I’m thinking a simple bindable event could work.

I’m overthinking a lot of this probably, but I just want to make sure what I’m doing is correct.

If you haven’t already, I highly suggest you read the API provided for DataStore2: API - DataStore2

Q1: Not quite sure what you mean by this, but you can combine keys (Cash, Banks, Kills etc.) in DataStore2 so that all of your data is stored in one place. By doing this you are saving all of your data into one big table but you don’t have to get the entire data table just to change one part of it. You can simply retrieve the intended data by using DataStore:Get("key") where key is the data you are trying to access.

Q2: I don’t think you can explicitly access past data. However, DataStore2 is pretty reliable and I doubt you will face many instances of data loss. This is due to how it saves data, which you can read about here: Saving Methods - DataStore2

Q3: A bindable event is not needed. DataStore2 comes with an OnUpdate() method which can be used to change values in your game whenever your data in the data store changes.

1 Like

For Q3 I meant for example a player bought a product and I want to store it in their datastore, I would use a bindable event which is connected to the main script that handles the datastore.

In that case then it would work. You could also require the DataStore2 module in the script that is listening for when the player buys a product and store the data that way as well, but of course it depends on how you want to structure your code.

1 Like