Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to list a database in order?

Hello, I am trying to make this script print the top 10 players with the most "Fans" so I can then make it display on a leaderboard within my game. I have been trying for a while now and I am confused. It only prints my name and my fans then it prints my userId and the number 1? I haven't told the script to even print my fans because I don't know how to do that so I am very confused. Any ideas?

local DataStoreService = game:GetService("DataStoreService")

local characterAgeStore = DataStoreService:GetOrderedDataStore("Savesss")

  

local pages = characterAgeStore:GetSortedAsync(false, 10)

while true do

local data = pages:GetCurrentPage()

for _, entry in pairs(data) do

print(entry.key .. ":" .. tostring(entry.value))

end

if pages.IsFinished then

break

end

end

2 comments

0

use an ordered datastore

0

and How do I do that?

1 answer

An ordered datastore is what you're looking for. Ordered datastores work like datastores but you can find the players' data in order.

You can create an ordered datastore by:

local OrderedDataStore = game.DataStoreService:GetOrderedDataStore("DataStore")

This discussion is preserved as it was. New answers, comments, and votes are closed.