Godot Tutorial

How to add an online leaderboard to your Godot game

By Chedz · Godot 4 & 3.6 · ~10 minutes

In this tutorial you'll add a working online leaderboard to a Godot game: one that ranks scores from real players, survives game updates, and validates scores on the server so a player can't just edit a local file and resubmit. No backend to host. We'll use CheddaBoards, but the shape of the steps is the same idea you'd follow with any leaderboard service.

What you'll need:


01Install the CheddaBoards plugin

Grab the plugin from the Godot Asset Store and drop the addons/cheddaboards folder into your project. Alternatively, search for CheddaBoards in the AssetLib tab inside the Godot editor (or on the Godot Asset Library) and let Godot import it into addons/.

On Godot 3.6? Use the 3.x SDK from GitHub (cheddaboards-godot3-addon): copy addons/cheddaboards/CheddaBoards.gd into your project and add it under Project Settings > AutoLoad with the name CheddaBoards, then skip step 02. Everything else here applies, with yield where Godot 4 uses await; the Godot 3.6 guide lists the differences.

02Enable the plugin

Go to Project > Project Settings > Plugins and tick the box next to CheddaBoards to enable it. This registers the CheddaBoards autoload so every script can call it.

03Register your game and connect

Create a free account in the developer console, register your game, and copy your Game ID and API key. Then set them and log the player in, once, wherever your game starts (your main menu's _ready() is a good spot):

func _ready() -> void:
    # Credentials come before any other CheddaBoards call
    CheddaBoards.set_api_key("cb_my-game_xxxxxxxxx")
    CheddaBoards.set_game_id("my-game")
    CheddaBoards.leaderboard_loaded.connect(_on_leaderboard_loaded)  # used in step 05

    # Wait for the SDK, then log in. Submits fail until login completes.
    await CheddaBoards.wait_until_ready()
    CheddaBoards.login_anonymous()

Players don't need an account: anonymous login gives them a persistent identity, and they can link Google or Apple later.

About the API key: it ships inside your build, so treat it as public. It identifies your game; it doesn't prove a score is legit. That's the job of the server-side limits you set in the dashboard's Security tab, plus the play sessions in step 06.

04Submit a score from GDScript

Here's the part that surprises people: it's mostly one call. When a run ends, pass the final score and streak to submit_score, and the score is submitted, validated server-side, and ranked automatically. (It needs the login from step 03 to have finished first.)

# Attach this where your run/round ends
func _on_game_over(score: int, streak: int) -> void:
    # No streak concept in your game? Pass 0.
    CheddaBoards.submit_score(score, streak)

That's the minimum. The SDK also emits signals as things happen (score accepted, leaderboard loaded, errors) so you can feed a live in-game HUD, but they're optional, not required to get a working board.

05Display the leaderboard

You have two options. The ready-made one is the full game template, which ships a leaderboard scene that renders ranked scores out of the box. The flexible option is to fetch ranked scores yourself and build a UI that matches your game's art: request the board, then render the entries when the SDK's signal delivers them:

# Request the board (sorted by score, top 100)
CheddaBoards.get_leaderboard("score", 100)

# Fires when the board arrives (connected once, in step 03's _ready())
func _on_leaderboard_loaded(entries: Array) -> void:
    for entry in entries:
        print(entry.rank, ". ", entry.nickname, " - ", entry.score)
Every signal and signature is in the signals reference, worth a skim before you ship.

06Turn on anti-cheat play sessions

Recommended before you ship. A play session tells the server a real run just started, so it can check each score against how long the run actually took. Start one when gameplay begins (not in _ready()) and clear it once the submit finishes; the SDK attaches the token to the submit for you:

func start_run() -> void:
    CheddaBoards.start_play_session()
    # ...your own game-start code...

# Connect score_submitted and score_error to these in _ready()
func _on_score_submitted(score: int, streak: int) -> void:
    CheddaBoards.clear_play_session()

func _on_score_error(reason: String) -> void:
    CheddaBoards.clear_play_session()

Then set your limits (score caps, streak caps, time validation) in the dashboard's Security tab. Without time validation switched on, the token is accepted but not checked, so wiring this up early costs nothing. The game template runs the whole session lifecycle for you. More in the anti-cheat guide.

07Test it

Run your game, finish a round, and check the dashboard. You should see your score appear. Play a few more times (or have a friend try it) so the board has more than one entry, then confirm the in-game leaderboard shows them in the right order.

08Optional: daily and weekly boards

These come built in. Every game gets all-time, daily and weekly boards by default, each resetting automatically on the calendar. Need monthly or a custom interval for a jam or season? Add it in one click from the dashboard. Old runs are archived and the board starts fresh each period. No extra code in your game: you just fetch the board you want.


Troubleshooting

Scores work in the editor but not in the exported build

Check that the code calling set_api_key() and set_game_id() runs in the exported build too, and if you load the values from a file, that the file is included in your export filters. On Android, also enable Project > Export > Android > Permissions > Internet, or no request leaves the device.

Nothing appears in the dashboard

Confirm the API key and Game ID are correct and that login_anonymous() has finished before the first submit_score(). If you've switched on time validation, every submit also needs a play session (step 06); the reason for any rejection shows up in the Security tab's suspicious-activity log.

Web (HTML5) build feels slow to start

That's typically the build's own load time, not the leaderboard call. Keep your export lean and the leaderboard request will resolve once the game is running.

Ready to add yours?

Grab the plugin and have a leaderboard running before your coffee's cold.

› Get the Godot plugin › More on CheddaBoards for Godot

Want the full picture, with achievements, player profiles, auth, and the REST API for other engines? Start at the Godot leaderboard overview or browse the documentation.