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!
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
-
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)}}
-
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
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.
-
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
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