Get all players' data - DataStore

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()

Thanks… I did eventually make it work:

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)

Glad to help out. Let me know if anything goes wrong and I’ll try to assist.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.