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


#142

Updated again after someone on Discord helped isolate the issue (Get() was calling OnUpdate for combined data stores).


#143

Thanks, I just found out about this and am definitely going to use it


#144

It’s the best


#145

I love this thing, I agree. It makes datastores that much easier.


#146

If you use DataStore2, please take this survey (and share it to your friends who use it as well) :slight_smile:


#147

Very useful and clean and helpful will be using this in the future.


#148

I’m going to implement this into my project tomorrow. Is good. :+1:


#149

When I was looking through your examples I was wondering which method I should be using and if there are any trade offs of each?

local CoinStore = DataStore2("coins", player) -- Ex: 500
local Inventory = DataStore2("inventory", player) -- Ex: {"Sword", "Torch, "Pick axe"}

or

local DataStore = DataStore2("data", player) 
--[[ Ex: {
     Coins = 500; 
     Inventory = {"Sword", "Torch, "Pick axe"};
}

Thanks!


#150

The latter is better for avoiding throttling and is what combined data stores do automatically. I recommend almost exclusively using combined data stores for that exact reason.

DataStore2.Combine("data", "coins", "inventory")

-- ...

local CoinStore = DataStore2("coins", player) -- Ex: 500
local Inventory = DataStore2("inventory", player) -- Ex: {"Sword", "Torch, "Pick axe"}

-- both CoinStore and Inventory save and get from data meaning
-- there's less throttling while also keeping sane code

#151

Ah, alright. I wasn’t aware of the DataStor2.Combine()… Thank you!


#152

I do not understand datastore2 keys that well can the key be anything? With normal data stores the key is a string. I am planning on implementing DataStore2


#153

I’ve consistently used alphanumeric with underscores with no problems (A-Z, a-z, 0-9, _). I don’t know the exact limitations, but that seems like a more than reasonable set of characters. You should be using string keys.


#154

I think that you have misunderstood my question. For example in Nezuo’s post he has this DataStore2("inventory", player) isn’t player the key or am I missing something?


#155

No, inventory is the key.


#156

I swapped them my bad. This is what confuses me

DataStore2 DataStore2(dataStoreName, player)
Example usage: local coinStore = DataStore2(“coins”, player)

Is that for player instances only?


#157

Yes. DataStore2 is entirely based on players.


#158

Thank you


#159

Hi, I am using DataStore2 in my game and I finally got accepted into the dev forum. :slight_smile: One question is regarding Combined data stores. If I am already using separate data stores, can I combine them now without losing any existing data?

For example (just using the same code from above), if my code is currently like this:

local CoinStore = DataStore2("coins", player) -- Ex: 500
local Inventory = DataStore2("inventory", player) -- Ex: {"Sword", "Torch, "Pick axe"}

People are already playing my game and have data. Can I now add the following line somewhere:

DataStore2.Combine("data", "coins", "inventory")

And in existing code sprinkled throughout the game, still use code without changing it (so it still looks like this):

local CoinStore = DataStore2("coins", player) -- Ex: 500
local Inventory = DataStore2("inventory", player) -- Ex: {"Sword", "Torch, "Pick axe"}

I think you said this is true, but I want to make sure before I do anything.

If yes, where/when should the Combine() function be called? Can I add it to any server script (that doesn’t have any delays)? Does it need to be called before any other call to Get/Set/Save data or is it order independent? Thanks!


#160

Do you have plans of adding support for non-player related stuff so that you can take advantage of the automatic retry for things like settings for reserved servers?


#161

No, you cannot, because of how combined data stores work. You would have to write a wrapper on your own.