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

Was experiencing a similar issue for a while and this version fixed it, thanks.

1 Like

now THIS… THIS IS ACTUALLY GOLD

Thank you.

Edit: after applying it to our game, there’s far less errors, thank you for making my life easy (even if I had to port old data to data store 2 which was kind of weird to program… Should I do a tutorial/example?)

4 Likes

Is it still worth using DataStore2? Or is it gone by now?

1 Like

Yes? I don’t know what you mean by “gone by now”.

6 Likes

What I mean is, Did the Roblox staff remove it? Are there still Datastore errors? So is it still worth using it?

1 Like

No.

Yes (although that’s not the main benefit of DataStore2).

Yes.

2 Likes

v1.1.0 is out which features a breaking bug fix: Release DataStore2 v1.1.0 · Kampfkarren/Roblox · GitHub

Previously when working with combined data stores, if the data store was empty then this code:

local dataStore = DataStore2(UUID(), fakePlayer)
dataStore:BeforeInitialGet(function()
	return "deserialized"
end)
print(dataStore:Get())
dataStore:Set("doge")
print(dataStore:Get())

…would print nil (because there was no data initially) and then “deserialized”, instead of the expected “doge”. This has been fixed. You are only affected by this bug if you use combined data stores and BeforeInitialGet on that data store.

The module will be updated relatively soon.

5 Likes

How does Datastore2 handle failed attempts to retrieve data from Roblox? Like, if it fails does it send something back to our scripts so we can kick the player or whatever we choose to do?

Please read the section on the backups API.

2 Likes

I’m probably missing something, but why does DataStore2 not automatically combine every key to a combined datastore?
Also, why are we allowed to choose the master key when the rest is completely internal?

1 Like

Because combined data stores haven’t always existed–combining all data stores now or making that the default would break backwards compatibility and lose people’s data.

Don’t have a great answer for this one, but it makes it easier to know what key you’re supposed to search for when using a data store viewer and makes it easier to separate combined data stores if you need to do that for storage space reasons or something similar.

3 Likes

I have a couple questions, hopefully I can format them correctly :worried:

So in the DS2.Combine(“”,“”,“”) function,

if you have

	local levelDataStore = DS2("Level", player)
	local coinDataStore = DS2("Coins", player)
	local gemDataStore = DS2("Gems", player)
	local winDataStore = DS2("Wins", player)
	local xpDataStore = DS2("XP", player)
	local xpnDataStore = DS2("XPN", player)
	local rebirthDataStore = DS2("Rebirths", player)

then you call

DS2.Combine("onemain","Level","Coins","Gems","Wins","XP","XPN","Rebirths")

It should save all those “DataStores” as:
“OneMainDataStore” --datastore
…Level --inside datastore
…Coins–inside datastore
…Gems–inside datastore
…Wins–inside datastore
…XP–inside datastore
…XPN–inside datastore
…Rebirths–inside datastore

Right?

rather than with out calling the .Combine() which would be:
“Level”–datastore
“Coins”–datastore
“Gems”–datastore
etc.

or am i dumb? if so, please explain :worried:

2 Likes

Yes–combining just makes them all save as one database but hides that aspect from the user.

3 Likes

User meaning the person writing the code correct?

And this would be avoiding the throttle right? If i were to have like 50 of them, then combine them all, it would all save as one correct?

Yes. The code for working with combined data stores should be the exact same as working without.

Yes.

2 Likes

You are honestly amazing. <3

I will absolutely be using DataStore2 in ALL of my games :slight_smile:

3 Likes

If Datastore2 does not work in Studio while testing, I am curious how people are debugging their games without constantly publishing to Roblox and testing in there, which is tedious and very time consuming.

It does, what made you think it didn’t?

1 Like

If I have a combined datastore like this:

    --Super Awesome Game Version 1.0
    DataStore2.Combine("PlayerData", "Tickets", "Inventory")

then in a later update add another datastore like this:

    --Super Awesome Game Version 1.1: The Level Update
    DataStore2.Combine("PlayerData", "Tickets", "Inventory", "Experience")

will the players who played before V1.1 keep their data from earlier versions?

1 Like

Yes. It uses :GetTable internally.

5 Likes