# Leaderboard

For examples on how to use, refer to [UIService](https://docs.easy.gg/scripting/bedwars-scripting/services/uiservice).

A leaderboard consists of entries (the rows displayed on the UI). Each entry has a key and a score associated with it.

* Keys refer to the names of what is being ranked on the leaderboard. You can add Players, Teams, or words (strings) to the leaderboard.&#x20;
* Scores are the number displayed next to each key. The leaderboard entries are automatically ordered by descending scores. The rank of a key is its place.

### Functions

#### getKeys(): Array<[Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string>

Returns the keys of the leaderboard.

#### addKey(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string, initialScore: number | nil)

Adds a new key to the leaderboard of the given type. You can optionally give the key an initial score, which otherwise defaults to zero.

#### removeKey(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string)

Removes the key from the leaderboard.

#### addScore(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string, amount: number)

Adds the given amount to the current score of the key.

#### subScore(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string, amount: number)

Subtracts the given amount from the current score of the key.

#### setScore(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string, amount: number)

Sets the score of the key to the given amount.

#### getScore(key: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string): number | nil

Returns the current score of the key. Returns nil if the key is not part of the leaderboard.

#### getPlace(place: number): [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player) | [Team](https://docs.easy.gg/scripting/bedwars-scripting/objects/team) | string | nil

Returns the key located at the place. Returns nil if there is no key at the place.

#### clear()

Clears all leaderboard entries.
