Getting all players data

now you see title what i mean, i looked devhub i found keys but getting selected player data, but i want get ALL PLAYERS data.

if you know how to get all players data please help me

What do you mean by all players?

i meant how to get all players data

All in a server, or every single player you have had?

every single player i have had

You will need to do a few steps, the easiest would just be having a OrderedDataStore. But if you don’t want to convert to an OrderedDataStore, no worries. There’s a function in DataStore that you can utilize.

DataStore:ListKeysAsync()

Which will return a list of all the Keys inside the DataStore. With that, you can iterate through the list and get a list of every existing data inside of your DataStore.

thanks i will try this, but i wanna ask this, this function get all players data?

It returns a list of existing Keys inside the DataStore. You will need to iterate through and get the data of each key to achieve what you are asking for.

i understand that, gets all player data and return a key?

i tried but i didnt understand abotu this listkeysasync()

script;

local DataStoreService = game:GetService("DataStoreService")

local options = Instance.new("DataStoreOptions")
options.AllScopes = true

local data = DataStoreService:GetOrderedDataStore("PlayerData", "Donated", options)

-- Search keys by prefix "house"
local listSuccess, pages = pcall(function()
	return data:ListKeysAsync("Donated")
end)
if listSuccess then
	while true do
		local items = pages:GetCurrentPage()
		for _, v in ipairs(items) do
			local value = data:GetAsync(v.KeyName)
			print("Key: ", v.KeyName, "Value: ", value)
		end
		if pages.IsFinished then
			break
		end
		pages:AdvanceToNextPageAsync()
	end
end
1 Like

That’s because :ListKeysAsync() is a DataStore function. You are currently using an OrderedDataStore, which has a different function to get the list of existing Data.

https://developer.roblox.com/en-us/api-reference/class/OrderedDataStore

Which you will use :GetSortedAsync()
https://developer.roblox.com/en-us/api-reference/function/OrderedDataStore/GetSortedAsync

you can tell me how to use GetSortedAsync?

There’s a perfect example in the wiki, I’ve also pasted it below.

local function printTopTenPlayers()
	local isAscending = false
	local pageSize = 10
	local pages = PointsODS:GetSortedAsync(isAscending, pageSize)
	local topTen = pages:GetCurrentPage()
 
	-- The data in 'topTen' is stored with the index being the index on the page
	-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
	for rank, data in ipairs(topTen) do
		local name = data.key
		local points = data.value
		print(data.key .. " is ranked #" .. rank .. " with " .. data.value .. "points")
	end
 
	-- Potentially load the next page...
	--pages:AdvanceToNextPageAsync()
end
1 Like

like this?

script;

local data = game:GetService("DataStoreService"):GetOrderedDataStore("PlayerData", "Donated")
local function printTopTenPlayers()
	local isAscending = false
	local pageSize = 10
	local pages = data:GetSortedAsync(isAscending, pageSize)
	local topTen = pages:GetCurrentPage()

	-- The data in 'topTen' is stored with the index being the index on the page
	-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
	for rank, data in ipairs(topTen) do
		print(data.key)
	end

	-- Potentially load the next page...
	--pages:AdvanceToNextPageAsync()
end

oh my failure, its function i forgor :skull: