> For the complete documentation index, see [llms.txt](https://mango-5m.gitbook.io/mango5m-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mango-5m.gitbook.io/mango5m-docs/resources/mango-achievements/features/leaderboard.md).

# Leaderboard

A server-wide ranking by achievement points, online or not.

A second tab in the trophy list ranks everyone on your server by achievement points.

Every character that has ever completed an award appears, **whether or not they are online**. Highest points first, ties broken by the number of awards completed.

## What a row shows

| Column | Meaning                                                            |
| ------ | ------------------------------------------------------------------ |
| Rank   | Position, with the top three picked out in gold, silver and bronze |
| Player | Character name                                                     |
| Awards | How many they have completed                                       |
| Points | Their achievement point total                                      |

The viewing player's own row is marked with an accent stripe and a **You** badge.

## Everyone can see where they stand

A player ranked below the visible cut still gets their own row pinned underneath the list. A player who has not earned anything yet sees an unranked row rather than being left out entirely.

## Settings

```lua
Config.Leaderboard = {
    enabled        = true,
    maxPlayers     = 0,     -- 0 shows everybody
    refreshMinutes = 5,
}
```

| Setting          | Does                                               |
| ---------------- | -------------------------------------------------- |
| `enabled`        | `false` removes the tab entirely                   |
| `maxPlayers`     | How many players to show. `0` shows all of them    |
| `refreshMinutes` | How often the ranking is rebuilt from the database |

{% hint style="info" %}
`maxPlayers = 0` is right for most servers. On one with tens of thousands of characters, set a number — the query deliberately fetches a little past the cut, so nobody who should have made the list is pushed off it by a late correction.
{% endhint %}

## Where the names come from

Your framework's own character table — `users` on ESX, `players` on QBCore and Qbox. Anyone missing from it falls back to the last name they were seen playing under, which is recorded on every load.

## How it stays cheap

The ranking is summed **by MySQL**, not by pulling every completed row into Lua: each award's point value is compiled into a single `CASE` expression built from your own definitions.

The result is then cached for `refreshMinutes`, so a hundred players opening the menu is still one query. Between rebuilds, anyone online has their own row corrected from memory — so a player never watches their own score go stale straight after an unlock.

## From your own resources

```lua
local top10 = exports['mango_achievements']:GetLeaderboard(10)
```

See [Server Exports](/mango5m-docs/resources/mango-achievements/developer-guide/server-exports.md).
