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

@Kampfkarren
I discovered the problem that some players are “losing data” (IF IT LOOKS LIKE MY CASE), I was basically thinking that I was not saving my data, but after a while I found that if you call the function :Increment () or :Set () at the same time in two different scripts it will not save correctly, it has to have a cooling of at least 0.1 seconds, I did it in my script and it is working now !! I just don’t know why you’re not saving with two calls, because before I updated my module it was working normally, what I think is that something from the new update is interfering with that …
Hope this helps.
(Maybe this was just happening to me!)

1 Like

As stated by @Kampfkarren, the free model is not updated anymore. Please use the version from the link above, that says “Download”

Where can I find the paid version.

Please read the documentation. There is no paid version, just a new way of getting it.

so … just like i said before in the script … that module is updated, i downloaded it then export it to roblox.

I was looking through the threat to find posts related to GDPR Erasure and saw that you wrote:

clear(userId, name)

This is very helpful, but I’m a bit confused on what you meant by using this in the command bar? I have edited DS2 so that it can support NoLoading on top of NoSaving to simulate a new player, however, how would I use that command in the command bar? Would I need to copy and paste this into the command bar via Dev Console with userId being the players ID and name is the name of the stat (such as “Gold” or “Level”)?

Yes, that is how you can get the latest version.

Are you asking what the command bar is on Roblox Studio or how to use my code with the command bar?

1 Like

Hello ! I have just a small question for you, is this a good way to use DS2.Combine ? I heard u said that if we use more than 1 main key, we are missing the concept of combine. Would this code cause more memory to be taken by the game ? Do i abolutely need to put everything under 1 main key ?

DataStore.DS2 = require(1936396537)

DataStore.NewPlayerDataTable = {
	Slot1 = DataStore.NewCharacterDataTable, 
	Slot2 = DataStore.NewCharacterDataTable, 
	Slot3 = DataStore.NewCharacterDataTable,
	Slot = DataStore.NewCharacterDataTable,
    Settings = DataStore.SettingsDataTable,
    Parameters = DataStore.Parameters
}

DataStore.DS2.Combine("DATA", "Slots")
DataStore.DS2.Combine("Slots", "Slot1")
DataStore.DS2.Combine("Slots", "Slot2")
DataStore.DS2.Combine("Slots", "Slot3")
DataStore.DS2.Combine("Slots", "Slot")
DataStore.DS2.Combine("Slots", "Settings")
DataStore.DS2.Combine("Slots", "Parameters")

-- ... in another script ... --

-- this is runned the first time a player joins the game to set the table in the memory
local SlotsStore = DataStore.DS2("Slots", player)
SlotsStore:GetTable(DataStore.NewPlayerDataTable)
SlotsStore = nil

Thank for reading ! :slight_smile:

This is what you said in post 187, I’m not entirely sure what you meant by using said command in the command bar.

I believe you can just do this:

DataStore.DS2.Combine("DATA", "Slots","Slot1","Slot2","Slot3","Slot","Settings","Parameters")

The way your doing is fine too.

HOWEVER, this wouldn’t work because your requiring the old datastore2 module. This one isn’t the latest version, so you will need to get it from the GitHub page.

Have a good day!

1 Like

No, it isn’t. You should only have one master key, and you should never use the master key directly.

1 Like

The command bar is a default part of Roblox Studio. Debugging | Documentation - Roblox Creator Hub

1 Like

Yeah, this is a pretty major issue for me. When a character in my game levels up, I update several stats and only a couple of them save. I don’t know what causes the behaviour, so I worked around it by updating the data locally and adding the value to be set in a queue, but that’s not a reliable or good approach. I’m wondering if this issue is caused by an improper setup, but as far as I know, I’m properly combining all my keys and doing what is required. weird

Your problem suggests otherwise. Does DataStore2 only print one key for “saved DATA” or something similar?

No, it prints out all the keys I’m using

Then you didn’t combine them before using them.

@Kampfkarren This is so cool ! But i have question, what does that do exactly? I mean, it avoids the loss of giving but how? And also this script use DataStore?

Found the issue, I was combining my keys properly and it was only printing out that it saved one key, but I was using .Changed to set the data. Setting everything manually works just fine

Is the :GetTable() function of this module recursive? For example, if I have a table already stored using DataStore2 and have the following data included:

classes = {
    assault = {level=0},
}

Could I then use the :GetTable() function to add to the assault table (as it is already inside the classes table)?

Example:

classes = {
    assault = {level=0, exp=0},
}

Overall question, would the exp value be added to the DataStore if the ‘assault’ class is already inside a table?