Coding For Kids & Teens

Scratch Lives Counter: Add Lives and a Game Over

A Scratch lives counter is five blocks of work and two bugs. The five blocks take about four minutes. The two bugs are the reason a child comes back to you saying the game is broken, and both of them come from the same place: a forever loop in Scratch runs about 30 times every second, and a child counting lives has no reason to expect that.

So the first touch of an enemy does not cost one life. It costs every life the player has, in roughly a tenth of a second, and the screen flicks straight to nothing. This guide builds the counter properly, names both failures with the mechanism behind them, and gets a Game Over on screen that actually stays visible.

If your child has not built a score yet, start with our Scratch score counter walkthrough, which covers what a variable is and why its scope matters. This guide assumes that and goes after the thing a score never has to deal with: an end state.

What is a lives counter in Scratch?

It is one number that only ever goes down, plus a rule about what happens when it reaches zero. That second half is the part that makes it different from a score. A score can climb forever and the game carries on regardless. A lives counter exists to end something, which means it needs a check and a consequence attached to it.

Make the variable from the Variables category, call it lives, and choose For all sprites. There is one lives total in a game, and every bat, spike and falling rock has to be able to change the same one. The alternative, For this sprite only, gives every clone its own private copy, which is the single most common reason a counter looks like it is resetting itself for no reason.

Why does a child lose all three lives in one touch?

Because of what a forever loop actually is. The Scratch Wiki describes the timing precisely: "The loop will wait until the next frame after each iteration, provided there are blocks running in the project that require a yield. At 30 FPS this delay is approximately 1/30 sec."

Now read the script almost every child writes first:

  • forever
  •   if touching Enemy then
  •     change lives by -1

Two sprites that have collided stay overlapping for far longer than a thirtieth of a second. A player cannot move away in under 33 milliseconds, and nothing in that script asks them to. So touching Enemy is still true on the next pass, and the next, and the next. One collision lasting a single second subtracts about 30 lives. With three lives, the game is over in roughly 0.1 seconds, which on screen looks like it ended the instant the sprites met.

Diagram showing a Scratch lives counter draining from three pips to zero within one tenth of a second because a forever loop with if touching runs thirty times per second
Three lives at 30 subtractions per second. The whole of the player's health is gone before the first frame of contact has finished looking like contact.

This matters for a reason beyond the bug. It is the first time most children meet the idea that a condition being true is not the same as an event happening once. A child who understands that goes on to debug half the problems in their next three projects without help.

How do you stop the drain?

Add one block directly underneath the subtraction: wait until not touching Enemy. The script now holds still at that line until the two sprites have genuinely separated, so the loop cannot reach the subtraction a second time from the same collision. One touch, one life.

Two other fixes work and are worth knowing, because which one you choose changes how the game feels:

  1. Wait until not touching. The player takes one hit and keeps standing where they are. Best for a platform game where being knocked back would be unfair.
  2. Move the player back to the start. Add go to x: 0 y: -120 after the subtraction. The sprites separate instantly, so the condition goes false on its own. Best for a maze.
  3. A short wait, around one second. Gives the classic flashing invulnerability window, and pairs well with a few repeats of hide and show.

What does not work is raising the number of lives. Thirty subtractions a second will eat ten lives as cheerfully as three, and a child who tries this learns the wrong lesson from it.

The five blocks that make a lives counter work

Here is the whole thing, with the two guards in place. Everything else is detail.

  1. when green flag clicked, so the game has a defined start.
  2. set lives to 3, which both starts the game and fixes the reset problem described below.
  3. forever, wrapping the detection.
  4. if touching Enemy then change lives by -1, the only line that costs the player anything.
  5. wait until not touching Enemy, the guard that makes one hit cost one life.

Then, inside the same forever loop and after the touching check, the end condition: if lives = 0 then show the Game Over state and stop. Use the = operator and compare against 0, not < 1. They behave identically here and the equals version is the one a child can read aloud.

Labelled vertical Scratch block script for a working lives counter showing when green flag clicked, set lives to 3, forever, if touching then change lives by -1, wait until not touching, and if lives equals zero, with the two guard blocks highlighted
Six bricks. The two in coral are the guards, and they are the two a first attempt leaves out.

Not sure whether your child is ready to move from following a tutorial to designing their own game logic? A free trial class with a Codeyoung teacher shows you exactly where they are and what they are ready for next, before you commit to anything.

Book a Free Trial →

How do you show a Game Over without freezing it first?

This is the second bug, and it is sharper than the first because the code looks right. A child writes the end condition like this:

  • if lives = 0 then
  •   stop all
  •   switch backdrop to Game Over

The backdrop never changes. The Scratch Wiki is exact about why: the stop block set to all"stops all scripts in the entire project" and "has the same behavior as clicking the stop sign." It is a cap block, which is why it has no notch on its underside, and nothing placed below it in a script will ever run. The backdrop switch is sitting in dead code.

Reverse the two lines. Switch the backdrop, or show a game over sprite, and only then stop all. The display happens, then everything halts with the message on screen.

Two Scratch block pairs showing the same two blocks in opposite orders, with stop all placed above switch backdrop producing a blank screen and switch backdrop placed above stop all producing a visible Game Over screen
The same two bricks, swapped. Stop all is a cap block with no notch underneath, so in the left version the backdrop switch is unreachable code.

There is a better pattern once a child is ready for it, and it is the reason broadcast blocks are worth learning around this point. Replace the stop with broadcast game over. Every sprite that needs to react can listen for it independently: the enemies hide, the player stops responding to keys, the backdrop changes, a final score appears. The player sprite stops being responsible for the whole ending, which is the first genuinely architectural decision most children make.

Note the third option on that dropdown too. stop other scripts in sprite is the only one of the three that is a stack block rather than a cap, so blocks below it do run. It is useful for killing a movement loop while an animation plays.

What breaks when the green flag is clicked again?

Scratch keeps variable values between runs. A game that ends with lives at 0 and no reset starts the next round at 0, so the player dies before they have moved. The child reports that the game only works once.

set lives to 3 under the green flag fixes it, which is why it is step 2 above rather than an afterthought. The same applies to everything else the ending touched: switch the backdrop back, show the sprites you hid, and send the player to their starting position. A reliable habit is to treat the green flag script as a list of every state the game can be left in, and undo all of it.

This is also the point where a lot of children discover their own ending by accident. Set lives to 1 temporarily while testing. Waiting for three deaths to check one line of code wastes a surprising amount of a child's patience, and deliberate shortcuts like this are a real part of debugging as a taught skill.

Where a lives counter goes next

Three extensions follow directly from what is already on screen, and none needs a new concept:

Show the lives, do not just count them. Tick the variable's checkbox for a readout, or hide it and use three sprites that hide one at a time. The second version is more work and reads far better.

Give a life back. A collectable that runs change lives by 1 turns a one-way counter into a resource the player manages, which changes the whole feel of a level.

Split lives from health. Health is a second variable that empties and then costs one life. This is where For this sprite only becomes correct rather than wrong, because each enemy clone genuinely does need its own health value.

If you want the order these ideas usually land in, the Scratch curriculum progression guide lays it out, and how to make a game on Scratch is a good complete project to put a lives counter inside.

Putting it together

A working lives counter is one global variable, a reset under the green flag, a subtraction inside the collision check, a wait until not touching guard, and an if lives = 0 ending that displays before it stops.

The two guards are where the learning is. Both exist because of timing rather than arithmetic, and a child who can explain why 30 frames a second breaks a naive counter has understood something that will save them hours in every project after this one. Let them hit the bug first, then fix it. It lands far better than being warned.

Codeyoung runs 1:1 live online classes for children aged 6 to 17, with a teacher who adapts the pace to your child rather than a fixed syllabus. The first class is free, so you can see how they respond before deciding.

Book a Free Trial

Sources: Scratch Wiki, Forever (block); Scratch Wiki, Stop () (block); block names and behaviour checked against Scratch 3 on 30 October 2026. Our Scratch classes for kids teach this progression in order.

Frequently Asked Questions

Why does my child lose all their lives at once in Scratch?
Because a forever loop runs about 30 times a second. While the sprites are still overlapping, the if-touching block is true on every pass, so change lives by -1 fires roughly 30 times per second of contact. Three lives are gone in about a tenth of a second.
How do you make a Game Over screen in Scratch?
Switch the backdrop or show a game over sprite first, then run stop all. Stop all is a cap block that behaves like clicking the stop sign, so anything placed below it in the script never runs. Put the display before the stop, not after it.
Why do my lives not reset when I click the green flag again?
Scratch keeps variable values between runs, so lives stays at whatever it ended on unless you reset it. Put set lives to 3 directly under when green flag clicked, along with the backdrop switch, so the second game starts in the same state as the first.
How do you add lives to a Scratch game?
Make a variable called lives for all sprites, set lives to 3 under the green flag, and put change lives by -1 inside the script that detects being hit. Then add two guards: a wait until block so one touch costs one life, and a check for lives = 0 that ends the game.
What block stops lives counting down too fast?
Wait until not touching, placed immediately after the change lives by -1 block. It holds the script still until the sprites have separated, so the loop cannot subtract again from the same collision. One touch then costs exactly one life.
Should the lives variable be for all sprites or this sprite only?
For all sprites. There is exactly one lives total in the game, and every sprite that can hurt the player needs to change the same one. This sprite only creates a separate private copy for each clone, which is the main reason a counter appears to reset itself.

Turn your child’s curiosity into creativity 🚀

Book a free 1:1 trial class and see how Codeyoung makes learning fun and effective.

Arpita Jain

Arpita Jain
I head curriculum design for Codeyoung's coding program. For the last 10+ years, I've built K-12 computer science curricula, and today I oversee the Scratch-through-Python pathway that thousands of Codeyoung kids learn on. The question I care about most is the one every parent eventually asks: what should my kid actually be learning at each age, and in what order? Too much kids' coding rushes children into typing real code before they're ready — and they bounce off it. I built our age-banded curriculum to do the opposite: logic and confidence first, with visual block coding, then real syntax once a child is genuinely ready for it.

Codeyoung Perspectives

Codeyoung Perspectives is a thought space where educators, parents, and innovators explore ideas shaping how children learn in the digital age. From coding and creativity to strong foundational math, critical thinking and future skills, we share insights, stories, and expert opinions to inspire better learning experiences for every child.