In this High Score in Pygame tutorial, we will improve our game by adding a High Score feature.
In the previous lesson, we added a Restart Game option. Every time the game restarted, the current score started from 0. But imagine this:
You collected 18 coins in one game. After restarting, your score became 0 again.
Now you don’t know what your best score was. That’s why many games display a High Score. A High Score tells the player the highest score they have achieved during the game session. By the end of this lesson, your game will display both:
- Current Score
- High Score
Let’s begin!
What You’ll Build Today
At the top of the game window, you will see something like this:
Score : 7
High Score : 15
Whenever you beat your previous record, the High Score will update automatically.
What is a High Score?
A High Score is the highest score achieved by the player.
Example:
| Game | Score | High Score |
|---|---|---|
| First Game | 8 | 8 |
| Second Game | 5 | 8 |
| Third Game | 14 | 14 |
| Fourth Game | 10 | 14 |
Notice that the High Score changes only when the player scores more than the previous best score.
Step 1: Create a High Score Variable
Near the score variable, add:
score = 0
high_score = 0
Here:
scorestores the current score.high_scorestores the best score.
Step 2: Update the High Score
Find the coin collision code.
if player_rect.colliderect(coin_rect):
coin_sound.play()
score += 1
coin_x = random.randint(0,736)
coin_y = random.randint(0,536)
Now add:
if score > high_score:
high_score = score
The updated code becomes:
if player_rect.colliderect(coin_rect):
coin_sound.play()
score += 1
if score > high_score:
high_score = score
coin_x = random.randint(0,736)
coin_y = random.randint(0,536)
This checks whether the current score is greater than the High Score.
If it is, the High Score is updated.
Step 3: Display the High Score
After displaying the current score, create another text.
high_score_text = font.render(
"High Score : " + str(high_score),
True,
(255,255,0)
)
Now display it below the current score.
screen.blit(high_score_text,(10,45))
Complete Working Program
This lesson uses the complete program from Lesson 16.
Only three changes are required:
1. Add the High Score variable
score = 0
high_score = 0
2. Update the High Score
if player_rect.colliderect(coin_rect):
coin_sound.play()
score += 1
if score > high_score:
high_score = score
coin_x = random.randint(0,736)
coin_y = random.randint(0,536)
3. Display the High Score
score_text = font.render(
"Score : " + str(score),
True,
(255,255,255)
)
high_score_text = font.render(
"High Score : " + str(high_score),
True,
(255,255,0)
)
screen.blit(score_text,(10,10))
screen.blit(high_score_text,(10,45))
Run the program.
Collect a few coins.
Notice how the High Score changes only when you beat your previous best score.
Restart the game.
The current score becomes 0, but the High Score stays the same.
That’s exactly how many real games work.
How Does the High Score Work?
Let’s understand this line carefully.
if score > high_score:
It simply asks:
“Is the current score greater than the best score?”
If the answer is Yes, we save the new High Score.
Otherwise, we keep the old one.
This simple condition is used in thousands of games.
Example
Suppose:
Current Score = 12
High Score = 10
The condition becomes:
12 > 10
This is True.
So the High Score changes to:
High Score = 12
Now suppose:
Current Score = 8
High Score = 12
The condition becomes:
8 > 12
This is False.
The High Score remains 12.
Mini Project
Update your game so it displays:
- Current Score
- High Score
Try to beat your own record.
Every restart is a new challenge.
Practice Challenge
Challenge 1
Display the High Score in green instead of yellow.
Challenge 2
Increase the font size of the High Score.
Challenge 3
Display:
New Record!
when the player creates a new High Score.
Common Errors
High Score always becomes zero
Check that you only reset:
score = 0
during restart.
Do not reset:
high_score = 0
unless you want to erase the player’s best score.
High Score never changes
Check that this code runs immediately after increasing the score.
if score > high_score:
high_score = score
High Score is not visible
Make sure you display the text before:
pygame.display.update()
Teacher’s Tip
Many beginners accidentally reset the High Score every time the game restarts.
Remember:
- Score belongs to the current game.
- High Score belongs to the player’s overall achievement.
Treat them as two different values.
What You Learned Today
Today you learned:
- What a High Score is.
- How to create a High Score variable.
- How to update the High Score.
- How to display the High Score.
- Why most games use a High Score system.
Key Takeaways
✅ Score changes every game.
✅ High Score changes only when you beat your best score.
✅ A simple if statement can create a complete High Score system.
Frequently Asked Questions
How do I create a High Score in Pygame?
Create a variable named high_score and update it whenever the current score becomes greater than the previous High Score.
How do I display the High Score in Pygame?
Use pygame.font.Font() to create text and display it with screen.blit().
Why does my High Score reset after restarting the game?
You are probably setting high_score = 0 inside the restart function. Reset only the current score.
What is the difference between Score and High Score?
The Score shows the points earned in the current game, while the High Score stores the best result achieved.
Can I save the High Score even after closing the game?
Yes. In the next lessons, you will learn how to save the High Score in a text file so it remains available even after closing the game.
Why do almost all games have a High Score?
A High Score encourages players to improve their performance and makes the game more enjoyable.
Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.
Shubhranshu Shekhar is a coding instructor, mentor, and founder of VSIT Delhi with 20+ years of teaching experience (since 2004). He has guided many students who are now working in multinational companies and specializes in Full Stack Development, Python, Digital Marketing, and Data Analytics.
