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

Do I have to “Combine” every single time at the top of every script I want to use DataStore2 in? I am speaking in respect to having referenced say, “KillStore_Version1” in 4 different scripts I wanted to use it in.

I don’t think it is necessary, because I don’t use it and it works well, just use the “Key” and the DataStore that you are going to use

Is manually combining keys required anymore? If not, how does it know what DataStore key to save to?

I’ll show you an example of how I use datastore2:

Power script:

DataStore2.Combine ("MyMasterKey", "Power")
--the code to modify datastore2 here

Speed script: (Another script)

DataStore2.Combine ("MyMasterKey", "Speed")
--the code to modify datastore2 here

sorry if i didn’t understand your question, i speak portuguese, and the translator is very confused

Ah yes. I do this too. I save my master key in a module of global variables and functions i use everywhere. Is this what you do too? :sweat_smile:

Combining keys is not 100% neccessary right now but it is good to practice using it as it will be the default way to use Datastore2, like it said here —>

To be clear, you should treat it like it is.

For the record, how does the module differentiate between keys of the same name? Say I had two datastores, one called Stats1 and another called Stats2, then suppose I had the following:

DataStore2.Combine("Stats1", "Kills")
DataStore2.Combine("Stats2", "Kills")

local KillStore = DataStore2("Kills", Player)
--Which store, Stats1 or Stats2 does it use the Kills key from?

Which key will it give me? Can I only combine and use one specific datastore per script in DataStore2?

Is this not true anymore?

Also, how am I able to utilize the Module when downloaded – I’m on a Mac and there’s no instructions saying what to do with the module source.

Don’t use more than one master key with Combine and you won’t have this problem. What you are describing is undefined behavior.

The documentation shows how to get the most up to date version of the module. I think I just need to remove that comment.

So you are saying that irrespective of the store, be it kills or something entirely unrelated like points, the master key shall save every single piece of data which I want to save under one huge data table?

Correct, that is the point of combining the data stores.

do you know of anyway I can use this with ordered data stores to make a game leaderboard?

How can i transfer data from main place to sub place or it is automatically done

im concerned about this topic being true

I think it is automatically done. My game has 2 places and all I did was just setting up a leaderstats, loading and saving the data.

Hi all, I was able to extend DS2 a bit by adding data modification of offline players. I modified __call to accept UserIds, which allows caching with the Id instead of player instance. When players leave, their data is saved using the UserId as cache key. There were minimal modifications to the module (primarily messing with DataStore2.__call). I tested this with admin commands like setting a player’s gold while they are offline, shutting down the server, and checking if the player has that much gold in a new server. I still accept Player instance as an argument, it’s only used to access Player.UserId now so I don’t have to modify every instance of the call.

2 Likes

Remember that the license requires that you open source any changes you make to the module.

I have found a problem with how Im saving data if the server shuts down, getting a lot of throttles in some cases. I will try to fix this and make a pull request

Do I still have to “combine” any key I use, or has this been updated to be automatic?