Godot Scoring System: How to Create One
In this article
To create a scoring system in Godot, you define a variable to store the score, add to it when the player earns points, and display it using a Label node. This guide walks you through the full process, including UI setup, code examples, and common pitfalls.
Understanding Godot’s Node System
Godot uses a scene tree where nodes inherit behavior from their parents. For a scoring system, you typically need:
- Label – to display the score on screen.
- Script – attached to a node (often the main scene or the Label itself) to manage the score value.
- Signal – to notify other parts of the game when the score changes (optional but useful).
In Godot 4, the default scripting language is GDScript. You can also use C#. The logic is the same: store a number, update it, and refresh the UI.
Step-by-Step: Basic Score Variable
Here’s the simplest approach. Attach a script to your main scene (e.g., a Node2D or Control node).
- Create a variable:
var score = 0 - When the player collects an item or defeats an enemy, increase it:
score += 10 - Update the label:
$ScoreLabel.text = "Score: " + str(score)
If you’re using a UI Label, make sure it’s a child of a CanvasLayer or Control node so it appears on screen. The dollar sign ($) is a shorthand for get_node().
Displaying the Score with a Label
In the Godot editor:
- Add a Label node to your scene.
- Set its text to something like “Score: 0”.
- Position it where you want (e.g., top-left corner).
- Give it a unique name like “ScoreLabel”.
Then in your script, reference it. If your script is on the same node as the Label, you can just do text = "Score: " + str(score). If it’s on a parent, use $ScoreLabel.text.
Adding Points with Custom Functions
Instead of scattering score += 10 everywhere, create a function:
func add_score(points: int):
score += points
$ScoreLabel.text = "Score: " + str(score)Then call add_score(10) when the player collects a coin. This centralizes the logic, making it easier to add animations or sound effects later.
Using Signals for Cleaner Code
Signals allow other parts of your game to react to score changes. For example, you might want to trigger a combo system or unlock an achievement.
- Declare a signal in your script:
signal score_changed(new_score) - Emit it inside
add_score:score_changed.emit(score) - Connect it to other nodes via the editor or code.
This decouples the score logic from the UI, making your game easier to maintain.
Common Mistakes and How to Avoid Them
- Forgetting to update the label – Always refresh the Label after changing the score.
- Using a local variable – If you define
scoreinside a function, it resets every call. Keep it at the script level. - Not using
str()– Concatenating a number with a string requires converting it to text. - Label not visible – Make sure the Label is under a CanvasLayer or Control node, and that its position is within the viewport.
Persisting the Score (Save/Load)
If you want the high score to survive closing the game, use Godot’s file system or built-in ConfigFile class. For a simple high score:
var high_score = 0
func save_high_score():
var file = FileAccess.open("user://highscore.txt", FileAccess.WRITE)
file.store_string(str(high_score))
file.close()Load it at game start similarly. The user:// path is a safe location for user data.
Advanced: Combo and Multiplier Systems
Many games multiply points based on consecutive actions. You can implement this by tracking a combo counter and a multiplier:
var combo = 0
var multiplier = 1
func on_enemy_killed():
combo += 1
if combo > 10:
multiplier = 2
elif combo > 5:
multiplier = 1.5
add_score(100 * multiplier)Reset the combo when the player takes damage or after a time limit. This adds depth without much complexity.
Frequently Asked Questions
How do I display the score as a rounded number?
Use str(round(score)) if your score can be a float. For integers, it’s already whole.
Can I use a ProgressBar instead of a Label?
Yes. Set the ProgressBar’s max_value and value properties. This is common for experience bars or health.
How do I reset the score when the player dies?
Set score = 0 in the death handler, then update the label. If you have a high score, compare and save it before resetting.
What if my score is stored in an autoload singleton?
Autoloads (singletons) are perfect for global scores. Create a script with var score = 0, add it to Project Settings > Autoload, and then access it from any script as Global.score.
How do I make the score float up when earned?
Create a temporary Label at the point of collection, animate its position upward, and queue_free() it after the animation finishes. Use a Tween for smooth movement.