How to use DataStore2 - Data Store caching and data loss prevention

Does this let me save the data as a table? If so, does it impede performance?

I was looking at CombinedDataStores and I think I’ve figured it out, however, how would I deal with things like dictionaries

E.g. my player data is

{
    Cash = 500,
    XP = 0,
    Backpack = {['ItemA'] = true, ['ItemB'] = true}
}

Would it just be easier if I combined the data table into Base10?

1 Like

As stated several times before, yes you can save tables just like how you can save them in normal data stores. With that player data, you should be just using combined data stores instead of doing it by hand (have a Cash, XP, etc stores).

Some of the questions I had was if this Datastore was efficient and organize. Turns out it’s not organized the best and I don’t have time to check if it’s efficient. However if you can answer that for me it’ll be great. I was thinking about remaking my own Datastore API with berezza’s method too. It’s the decision factor though if I should use this as my base or start from scratch.

1 Like

I’m really not sure what you’re asking? DataStore2 has never been noticably slow and one of the most expensive parts of it had its speed increased by several magnitudes with the new Lua VM.

Thank you, will be just using Datastore regularly then. As an OCD as my unasked for condition, I hate how it prints (“saved “…Datastore) in the console when it’s being saved. Maybe an option to disable that? I’d love to do it myself but I’d be missing the latest updates

If you make an issue for it on the GitHub, I can do it.

Sure thing, will do it in a few minutes

If I were to make a script that would give players free points when the game is about to shutdown, will the coins I gave the player still save or not?

As long as it runs before DataStore2 saves in :BindToClose, yes. You can even call :Save() after to guarantee it.

Okay few questions and I’m not sure if they’ve been asked previously.

  1. I understand the concept of .Combine but wouldn’t it just be easier to make this an automated process in the datastore itself instead of us continuously .Combine ing just so that data won’t throttle?

  2. Following to that question, how does combining the datastore exactly work when trying to get that datastore? Once we combine then is there a way to separate them?

  3. As the “concerns” for the module specially from the thread itself, won’t this create a bunch of empty datastore/orderreddarastores because of the os.time as the name/key of them? I would like to see this module to be more futureproof because as stated as a comment before, you’d be fired if you made this module because of the empty and “memory leak” concept.

  4. I know this might be just a misconception, but the whole point of this module is to guarantee or at least maximize the chances of the data being stored. Does this mean even if the Roblox servers are down, will the data save? Obviously from my point of view, no probably not because it’s down- you cant do anything about it.

This is planned.

It’s the same fundamentally as just doing DataStore2("data", player) where “data” is just a table of every other store. It means getting/saving only has to be done on one store no matter how many you have, as opposed to doing so for each. It’s an ergonomics feature.

Technically, yes. You could use DataStore2 on the master key and extract it there, then set it to the new uncombined data store. I just don’t see a point in it.

Yes. Roblox just doesn’t seem to care. Data servers are ridiculously cheap. Making the current data saving method optional is planned.

Nope. That’s impossible without resorting to HttpService (which will probably go down with high traffic more than Roblox data stores, also a host of other architectural issues). You will, however, be able to Get (assuming data stores were up the first time you do it), Set, update, etc.

3 Likes

Thank you for those answers!

I do still have questions about the current combination system (this can be discarded after the new system is made)

What I meant by uncombining datastores was specifically meant how to exactly extract the Datastore from the masters automatically? Combining is practically serialization to prevent throttles and I’m unaware of the deserialization part of this.

For example, let’s say I have two tables with two different datastores I need to save, one for my player stats (exp, quest progress, inventory) and my leader stats (coins, cash, level). Let’s say they were all serialized before sending a save request. Next I combine the two Datastores. When my player joins back how would I effectively be able to get these saved values back?

Sorry I don’t understand enough because I haven’t properly tested this yet. I’ve been typing all of my replies on mobile.

1 Like

The same way you would if it wasn’t combined–combined data stores should not impact use at all. BeforeInitialGet/BeforeSave just like without.

2 Likes

Thanks I’ll be testing these out when I get back on my computer.

2 Likes

Just to clarify, the whole point of this Datastore is to maximize the speed to get the data stored.

Then when saving… backing it up and saving asynchronously in order to prevent data loss other than ROBLOX themselves going down?

Sounds more understandable, but if you can explain more of what this Datastore changes exactly. (also if you’re able to give me the release date of the planned combination system)

3 Likes

It’s been out for several months. It says so in the OP.

The whole point of DataStore2 is the caching, yes. The backup saving is just a bonus (and will be made optional in a future update).

3 Likes

Refactor testing!

I’m working on a big code refactor. The point right now is just to make the code cleaner, you should not have to change any code.

I would really appreciate if existing DataStore2 users could test this version and make sure everything works exactly like it did.

Once any issues are identified, I’m going to publish this on the main free model and hopefully the package works this time.

Edit: Not sure why, but it’s not for sale. Oh well.

7 Likes

I am a bit confused on backups. I have my data working just fine, saving and loading and now am looking to implement the backups.

coinStore:SetBackup(3)

If it reaches the maximum amount of retries, does it just prevent data from saving? Also it says it will set the value of the data store to the value provided. Does that mean if the game fails to get its data X amount of times, their data will become nil if no value is passed? Confused I am.

3 Likes

Yes, and treats :Get() like the player didn’t have data.

No, because it won’t save. :Get() will return nil though if you don’t provide a default value AND it fails.

3 Likes

Can i transfer my existing datastores to datastores 2?

1 Like