:GetCurrentPage() returns an empty table

so i’m working on a global leaderboard system (for wins) but for some reason when i try retrieving the top 10 players it instead retrieves me an empty table (even though there’s hundreds of data entries already saved in my game (for wins) so i don’t know why it keeps returning empty tables)

i’ve also looked into some other posts which were exactly about this problem i have but it still didn’t work

here’s the code:

local DSS = game:GetService("DataStoreService")
local ODSWins = DSS:GetOrderedDataStore("WinsStore")

while task.wait(5) do
	local page = ODSWins:GetSortedAsync(false, 10):GetCurrentPage()	
	print(page) -- (i also tried looping through the entire table but it didn't print anything at all)
end

there are no errors in the console (as it only prints out an empty table)
any help is appreciated

How are you saving the data? It’s likely that the issue is with the saving.

all of the data is properly saved (here’s an example):
Ekrano kopija 2024-07-01 140734

and here’s some code that saves data:

game.Players.PlayerRemoving:Connect(function(plr)
	local plrId = "Player_"..plr.UserId
	local s, f = pcall(function()
		winsStore:SetAsync(plrId, plr.leaderstats["Wins 🏆"].Value)
		blocksStore:SetAsync(plrId, plr.leaderstats["Blocks 🧱"].Value)
		diamondsStore:SetAsync(plrId, plr.leaderstats["Gems 💎"].Value)
		ownsRed:SetAsync(plrId, plr.TrailsOwned.Red.Value)
		ownsGreen:SetAsync(plrId, plr.TrailsOwned.Green.Value)
		ownsBlue:SetAsync(plrId, plr.TrailsOwned.Blue.Value)
		ownsYellow:SetAsync(plrId, plr.TrailsOwned.Yellow.Value)
		ownsCyan:SetAsync(plrId, plr.TrailsOwned.Cyan.Value)
		ownsPurple:SetAsync(plrId, plr.TrailsOwned.Purple.Value)
		claimedRewardData:SetAsync(plrId, plr.ClaimedReward.Value)
	end)
	if not f then
		return
	end
end)

You have to use OrderedDataStores when saving, not just when loading.

i’ve tried that but it still returns me an empty table

Then I don’t think you have tried it, at least not properly. What code did you use when attempting to save it with OrderedDataStores?

task.spawn(function()
	while task.wait(5) do
		local ODSWins = DSS:GetOrderedDataStore("WinsStore")
		winsStore:SetAsync(plrId, wins.Value)
		local page = ODSWins:GetSortedAsync(false, 10):GetCurrentPage()

		print(page) -- (i also tried looping through the entire table but it didn't print anything at all)
	end
end)

(i’ve also tried changing up the order of where setasync() is placed but it still returned me the same result)

You need to save it with ODSWins:SetAsync()

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