As most of you know, datastores dont let you get a list of all keys in a datastore.
This is why i created this module. Whenever you assign a key in a datastore, you just call this module function and it stores it for you.
Then when you need a list of all keys, like seeing the amount of items stored in the entire datastore, money, etc. you call the GetKeys function.
I know ordereddatastores are a thing but it doesnt really go far from ordering them. This is why i created this. (I was also bored so ye)
Source:
local module = {}
local dds = game:GetService("DataStoreService")
module.COUNTER_KEY = "DatastoreKeyStorage"
function module.CreateStorage(datastorename)
local curStorage
pcall(function()
curStorage = dds:GetDataStore(module.COUNTER_KEY):GetAsync(datastorename)
end)
if curStorage then
return
end
dds:GetDataStore(module.COUNTER_KEY):SetAsync(datastorename,{})
end
function module.AddKey(datastorename,key)
local curStorage
pcall(function()
curStorage = dds:GetDataStore(module.COUNTER_KEY):GetAsync(datastorename)
end)
if curStorage then
dds:GetDataStore(module.COUNTER_KEY):UpdateAsync(curStorage,function(p)
table.insert(p,key)
return p
end)
end
end
function module.GetKeys(datastorename)
local curStorage = {}
pcall(function()
curStorage = dds:GetDataStore(module.COUNTER_KEY):GetAsync(datastorename)
end)
return curStorage
end
return module