i tired all is written but i didn’t understand, can you do it for me? i want it to load all the keys in the datastore
for examples banned ones, it’ll get all of their ids
If I understand what you are trying to do here- you are wanting to pull all player’s (who have data stored) user ID & saved inventory. Correct me if I’m wrong on that.
To do this you could have a function as so- format and replace variable names how you deem fit!
-- Call DataStoreService and set an AllScopes parameter for later use
local dataService = game:GetService("DataStoreService")
local options = Instance.new("DataStoreOptions")
options.AllScopes = true
local DataStore = dataService:GetDataStore("<Insert Data Store Name Here>", "", options)
-- This will be used to store the retrieved userIDs and Inventory
-- Each key will be a players userID, and the content of the key will be their inventory!
local dataDictionary = {}
-- Get all the stored keys under our Data Store
local listSuccess, pages = pcall(function()
return DataStore:ListKeysAsync()
end)
-- If the pcall succeeds without error, then this will run.
-- The loop will go on until all key values have been read through.
if listSuccess then
while true do
local items = pages:GetCurrentPage()
for _, v in ipairs(items) do
-- Take current key + its associated value and write it into the dictionary.
local value = DataStore:GetAsync(v.KeyName)
dataDictionary[v.KeyName] = value
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
end
For the code listed above to work in the way you want it to, the key used to store a player’s inventory under must be their UserID. As you wanted, it will neatly put everything into a dictionary table (dataDictionary) for you to access and use how you want!
This was my first ever forum post, so please correct me if there is anything clearly wrong here. Other than that though, if you are still confused with any of the comments I put in the code or have any questions- I’ll try to help you out the best I can!