How does the leaderboard work?

So im needing to make a “leaderboard” system that displays everyones stats very quickly (just in one server) currently I am using Ordered Datastores but these take to long to update/change (6 seconds between sending.) and i need the “leaderboarding” done in like 1 second.

So im wondering how the Core-GUI’s leaderboard does it. Please help! :slight_smile:

I usually manage all stats in a table server side. Every time a user stat is updated and checked for validity the leaderboard stat is changed. Here’s a great article on leaderboards.

Here’s the type of table I use to store data.

You seem to know datastore, I save the players data every x seconds and when they leave. I simply load the table data if their datastore exists.

thats not my issue my issue is i need to know how the leaderboard finds the player with the most KO’s (or something) else ranks them first, finds the second person, ranked them second etc.

1 Like

It takes a list of all players in the server and their corresponding stats, and then sorts them according to one of those stats. It’s not cross-server and it doesn’t use datastores.

how does it sort them… thats my question.

1 Like

so how would i do this?

local data = {}
for i,x in pairs(game.Players:GetPlayers()) do
for i,x in pairs(data) do
x = math.random(1,3)
for i,x in pairs(data) do

1 Like

so this is the code I have but instead it makes it so the person with the most gold goes second and the person with less gold goes first and sometimes the second player is labeled as “nil”

You wanna use table.sort to compile a leaderboard.

I believe you’re looking for this:

1 Like