How to use GetCurrentPage?

Hey devs, I want to make a global leaderboard and in most scripts they use GetCurrentPage. Any help is appreciated Thanks!

An OrderedDataStore for things like Top 10 / Top 100 Leaderboards, uses a Pages system so you can display the list in sections. :GetCurrentPage() is called to get the page you need from the list.

Here is a brief example of what this would look like:

local TopMoney = game:GetService("DataStoreService"):GetOrderedDataStore("TopMoney")
local GetTop10 = TopMoney:GetSortedAsync(false, 10)
local CurrentPage = GetTop10:GetCurrentPage()
for _, data in pairs(CurrentPage) do
     print(data.key) -- this would be the key used to store player's data, such as their userId.
     print(data.value) -- this would be their score saved (in this example, the money)
end

You can get more info by clicking [here]

Hope this helps!

2 Likes

How many pages does GetCurrentPage return

:GetCurrentPage() returns the current page, which is only one, hence itself.

If you desire to collect more pages, determine if not GetTop10.IsFinished, and utilise the approach of moving on to another page with GetTop10:AdvanceToNextPageAsync().

1 Like