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

I don’t know what you’re asking, but you need to call :Get() to get data.

I am not sure what you are saying, can you elaborate?

I mean, can you save values name, not just there value. Also, can you save an inventory system with this?

You can save whatever you can do in data stores. I’m not sure what you mean by “saving the values name, not the value”.


https://gyazo.com/15a867a070a3b5142ccdec3547a88259

Yes, it’s still possible for DataStore2 to throttle, especially if you call :Save() often. Not sure what this is meant to show.

1 Like

How do i use Increment on table values?, i have my IntValues set to my table.

You don’t. Just use Get and Set manually.

What would be the way of manually changing a Dictionary value that is more than one layer deep without resetting it with a new value by using :Set(newValue: any)?

Just call Get, manipulate it however you want, then call Set again. DataStore2 doesn’t treat tables any differently.

Oh, okay. Thank you very much for the fast response.

Is there a correct way to get a whole combined datastore as a table in one go rather than calling :Get() on every key? I had been using something like this

local defaultTable = {["Wins"]=0, ["Points"]=0, ["Deaths"]=0}
local DataStore2.Combine(MASTERKEY, "Wins","Points","Deaths")

function SetupData(player)
	local data = DataStore2(MASTERKEY, player)
	local sessionTable = data:GetTable(defaultTable)
        -- do stuff with the data retrieved
end

But the API states that referencing the masterkey this way is not defined. Is there any increase in risk of losing data by using a single key to store a table of data and updating the whole table whenever a value is changed rather than updating each seperate key in a combined store individually?

Also is there a solution to this closed issue or is adding a wait the only fix as of yet? Combined data stores mixing state when receiving remote events · Issue #76 · Kampfkarren/Roblox · GitHub

The “SaveAll” method is consistently erroring.

DataStore2 is referenced as “ds2”. I have used “Datastore2.Combine(main,x,y,z)” when the player joins, so all the data is combined. Here is an excerpt of code that is erroring that I have in a developer product purchase:

local function addFunds(playerId, amount)
local player = Players:GetPlayerByUserId(playerId)
local playerData = ds2("Ints", player):Get()
playerData["Zombucks"] = playerData["Zombucks"] + amount
ds2("Ints", player):Set(playerData)
ds2.SaveAll(player)
return true
end

I have recently had issues with people losing data when I shut down the server, so I am now intending on saving data manually when it changes. When I call ‘ds2.SaveAll(player)’ like the API suggests, I get the following error:

ServerScriptService.GamepassDevProduct:38: attempt to call a nil value

This would suggest that the player object is nil, which is not the case. I believe something with DataStore2 SaveAll is faulty? Or am I implementing it wrong (in which case the documentation might need adjusting!).

No, but it’s pointless. You do this with normal data stores out of necessity, not because it’s the best approach as the programmer. DataStore2 makes using multiple keys easy, so there’s no real reason not to just do that.

You are likely on an older version. If you used the free model which is not updated anymore. Get the latest release on GitHub.

1 Like

Can i see an example???

Is there anyway to revert back to a save like 2 days ago? I just had an exploiter come in the game (Not my game but a dev team I work for) and since our game had a backdoor, they ended up giving a bunch of people infinite money. I just wanna know if I can go back to the save before that happened. Everything in datastore2 is setup, and has been running for months.

DataStore2 is amazing and i use it in some of my games
Game with DataStore2: Find The Way {Alpha} - Roblox

1 Like

What is the recommended way to handle multiple scripts calling :Set() in quick succession? I am having issues with mixing states when this occurs, and putting wait(1) before calling :Set() in one of the scripts seems inefficient and unreliable to me.
For example, in a game where a player gets points for shooting another in one script, and also gets points when the game is over in another, how would you advise tackling the situation that arises if a player shoots another which immediately triggers the ending of the game - causing the mixing of states when :Set() is called rapidly?

local data = dataStore:Get()
data.Value = data.Value + 1
dataStore:Set(data)