How To Get All Saved Data In A DataStore

How To Get All Saved Data In A DataStore!

Hello there! Have you ever tried to get ALL saved data in a DataStore? With this handy module I have made, it is now possible! :partying_face:


Nice nice, what can it do?

Well, I’m glad you asked! This new and enhanced DataStore works just like the same, old, DataStore. It has the same functions, and new ones, which are listed below! Also, when you update data, it will return the saved data! BTW it is not an instance, it is all in a table.

DataStoreService Functions

  1. dataStoreService:ListAllDataStoresAsync() – returns a dictionary of all the “enhanced” data stores with new functions

Here is an example:

local dataStoreService = require(workspace:WaitForChild("DataStoreService")) -- path to module
local data = dataStoreService:GetDataStore("PlayerData") -- making a datastore
print(dataStoreService:ListAllDataStoresAsync()) -- returns {["PlayerData"] = {(table with functions)}}
  1. dataStoreService:ListAllDefaultDataStoresAsync() – returns a dictionary of all default data stores

Here is an example:

local dataStoreService = require(workspace:WaitForChild("DataStoreService")) -- path to module
local data = dataStoreService:GetDataStore("PlayerData") -- making a datastore
print(dataStoreService:ListAllDefaultDataStoresAsync()) -- returns {["PlayerData"] = PlayerData (instance)}

lame there was only 2 :confused:


DataStore Functions

Uhm, please don’t get upset but, the enhanced DataStores have only one new function, listed below. Read the downside lower below explaining why I cannot make more functions.

  1. dataStore:GetAllSavedAsync() – returns a dictionary of all the saved values in the data store

Here is an example:

local dataStoreService = require(workspace:WaitForChild("DataStoreService")) -- path to module
local data = dataStoreService:GetDataStore("PointsData") -- making a datastore
data:SetAsync("Stickmasterluke", {points = math.random(1, 100), totalPoints = math.random(100, 200)})
data:SetAsync("Shedletsky", {points = math.random(1, 100), totalPoints = math.random(100, 200)})
data:SetAsync("builderman", {points = math.random(1, 100), totalPoints = math.random(100, 200)})
print(data:GetAllSavedAsync()) --[[ returns:
                    ["Shedletsky"] =  ▼  {
                       ["points"] = 2,
                       ["totalPoints"] = 114
                    },
                    ["Stickmasterluke"] =  ▼  {
                       ["points"] = 81,
                       ["totalPoints"] = 197
                    },
                    ["builderman"] =  ▼  {
                       ["points"] = 16,
                       ["totalPoints"] = 130
                    }
     ]]

extremely lame there was only 1 :mad:


Downsides

There is just one downside, and it affects a lot.

This “enhanced” DataStore is actually slower than the regular DataStore. That is because when you request to update data, behind the scenes it has to save it twice; one for the DataStore you are using, and another DataStore for all the saved values. This is why I cannot make more functions for the DataStores because it will be very, very, slow.

Luckily,
If you still want to use this as your normal DataStore, you still can by disabling the command! Fire:

local dataStoreService = require(workspace:WaitForChild("DataStoreService")) -- path to module
dataStoreService:ToggleGetAllSavedAsync() -- toggles ":GetAllSavedAsync" function and disables it (default is enabled)

or you can fire:

local dataStoreService = require(workspace:WaitForChild("DataStoreService")) -- path to module
dataStoreService:DisableGetAllSavedAsync() -- disables ":GetAllSavedAsync" function

Both of these disable the command, and it will prevent the script from saving twice in the background, so it will work just like normal DataStore. Also, when you save data, it will not return the saved data. If you want to enable it, run :ToggleGetAllSavedAsync or :EnableGetAllSavedAsync()


Thanks for reading!

Thank you so much for reading! If this post gets a lot of attraction, I might make a plugin for this! Please be sure to leave any feedback or suggestions, it is much appreciated! Here is a link to the module:
https://www.roblox.com/library/6435574495

6 Likes

I was gonna make a similar system to allow ListKeysAsync() and ListDataStoresAsync() before it was released. (I want it so much ugh)
About the thing about it being slower every function, just wrap the ordered data store indicator inside a coroutine and keep retrying for like 5 times or until it worked.

You still can make your similar system, it doesn’t really matter to me!

Also, all the data stores are stored in one big table, in another data store (Global). When you list all the values of a DataStore, it gets the big table, finds the DataStore’s name, and returns that. When you fire dataStoreService:ListAllDataStoresAsync(), it gets the big table again, formats it in another table, then returns that.

May I remind you that ListDataStoresAsync is not enabled right now, the flag DFFlag::DataStoresV2Enabled is disabled, and even if you enable it, it checks the universe on a filter on the server, and there are only 2 places that have it enabled.

Oooh… That isn’t what you should be doing… That’s quite expensive and prone to loss and inaccuracy, and certain people’s systems could glitch because of it. You should be using OrderedDataStores instead, and listing them, and giving the ordered listing object, OR giving a proxy to it, and renaming certain stuff. Like info.key and stuff to info.DataStore.

Yes, I know that. I made a custom command for that, so it does not use the default DataStoreService:ListDataStoresAsync()

1 Like

The only downside here for your system would be the fact that you can’t have a prefix to a datastore or key;

Ah, alright, didn’t understamd what the context was, got mistaken

1 Like

I don’t really know how I would implement this, because OrderedDataStore only accepts integers (to my knowledge).

Have the key as the datastore name and the value as os.time() (for datastores)

For keys, everytime you set a key, set the key, as… The key, and value also to os.time()

The dataStoreName for the key listing should be : dataStoreName/KeyListing

1 Like

Then maybe have some functions for Getting the data, like :GetDataFromKeyAsync() or something. I could make a fork and send it to you;

1 Like

I’ll try that out, and give you an update. Thanks!