Hello! I want to get all of the player data for a leaderboard I’m working on.
I have been trying to understand DataStore:GetKeysAsync() but I don’t know how to use it properly.
Here is my code:
local ds = game:GetService("DataStoreService")
local playerData:DataStore = ds:GetDataStore("PlayerData")
local player = game.Players:WaitForChild("MINIGAMERD2011")
function getAllPlayerDataOfGame()
-- I dont know what to do here
end
wait(2)
getAllPlayerDataOfGame()
local doors = {
}
local listSuccess, pages = pcall(function()
return playerData:ListKeysAsync("Player_")
end)
if listSuccess then
while wait() do
local items = pages:GetCurrentPage()
for i, v in ipairs(items) do
local value = playerData:GetAsync(v.KeyName)
--print("Key: ", v.KeyName, "Value: ", value)
local name:string = v.KeyName
name = name:gsub("Player_", "")
doors[name] = value["Doors"]
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
end
table.sort(doors)
print(doors)