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

What is better to use?
require(id) or just put it in server script service and require it from there?
(What do you suggest mainly?)

2 Likes

It’s better to require the module directly from serverstorage (or another place where you’ve put the modulescript). If you require by ID you have the risk that code could be pushed which results in backwards incompatability with code which is not prepared for it.

1 Like

Is there anyway to see whole list of options?
Like it’s shown in AlvinBlox’s video.

1 Like

If you are referring to all APIs of DataStore2, follow this link.

The part you have selected is the :SetBackup() API which can be used to set a maximum of tries to get data from the roblox datastores.

1 Like

Is there any way to access the same datastore through multiple scripts?
Also tables

1 Like

Yes, you can access them the same way you do in all scripts.

2 Likes

Is there any quick hand to updating the value of a dictionary inside of the data table? My code right now is

local dataStore = ds(key,plr)
local data = dataStore:GetTable(defaultData)
data.stats.missedFlights = data.stats.missedFlights + 1
dataStore:Set(data)

I’m not sure if I’m missing anything

1 Like

This should be alright. You could however choose use .Combine() with seperate DataStores to easily access them without calling the whole table, changing one value and setting the table. This way you could also use for example Datastore:Increment(value)

1 Like

When downloading the rbxmx file of DataStore2, does it automatically update or what is the best way to get an up-to-date copy of data store 2.

I have been doing it manually every week.

1 Like

Just watch the repository on GitHub for releases, you’ll get a notification when it updates.

2 Likes

One other question: Is it possible to manually edit data using Crazyman32’s data store editing plugin? I’m using :GetTable and storing everything as one table. If so what’s the datastore name and key? Asking because I plan on hosting events and stuff that give users rewards. I looked through the code and I’m not quite sure how to access the data.

Edit: Got it. Will the number always be 1 or does it change? Code mentions os.time() and I’m not sure how that applies here.

1 Like

Is an actual value needed for datastore2 to work?
By that, I mean, if you actually need to put an IntValue in ServerStorage for example and after that, it can save, or can you just save number,string or bool data without any actual value in explorer?

It’s not always 1. Please read this on using the data store editor: How to use DataStore2 - Data Store caching and data loss prevention - #287 by Kampfkarren.

Value objects are never used in DataStore2 except for the SaveInStudio flag.

This is not an issue related to the module. I’d recommend starting from the Roblox Developer Hub.

I’m currently working on a new project and I was wondering if its recommended to use the OrderedBackups or Standard setting.

Personally, I haven’t had any problems using OrderedBackups, and it’s saved me a few times when players report data loss (because I use the module incorrectly) and I can easily revert their data back. It’s also battle tested, I’m not sure if any high profile games use Standard. My suggestion is if you use plenty of other ordered data stores, Standard is your only choice. Otherwise, use OrderedBackups.

2 Likes

Is it ok if I take some data (value, string, bool) a few times (more than usual). Will that cause lag? By “more than usual” I mean, if somebody clicks a button, it would request data, if someone dies and respawns, etc. What’s suggested limit if so?
2nd: Is there still chance that users lose their data?

2 Likes

:Get() only calls a data store request the first time you use it, and :Set() calls data store requests never. Using methods frequently is essentially the same as just setting a variable, so you’ll be fine.

1 Like

@Kampfkarren
Is there any function that is similar to this

local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore()
local 1To100 = DataStore:GetSortedAsync(false, 10)

What I mean is
I’m trying to get the data from the server and transfer it to the client and my issue will be fixed if there is a similar function like :GetOrderedDataStore() I need a similar function for this to function my leaderboard.

EDIT: Using The :Get() Function Will Not Work I need the function to be global not local and is there a Similar Function Like :GetSortedAsync().

Sorry for the bad English.

Reminder: Check the code for better towards on understanding my problem

Thanks.