Coding For Kids & Teens

How to Make a Clicker Game in Scratch: Step by Step

A clicker game in Scratch is the smallest project that contains a whole economy: something you click to earn, a shop that spends what you earned, an upgrade that earns for you while you watch, and prices that climb so the game never runs out of goals. It looks simple and it is, but every one of those parts teaches a real programming idea, and three of them hide bugs that most tutorials never mention.

This guide builds an original game called Gem Miner. The player clicks a crystal to mine gems, buys a better pickaxe to earn more per click, and buys mining robots that dig one gem a second each. Every step ends with what should happen when your child clicks the green flag, so they can check their own work before moving on. For parents: by the end, your child will have used variables, if-else decisions, a loop that runs on a clock, and multiplication by a decimal, in a game they will actually want to keep playing.

Key Takeaways

  • The whole game runs on five variables: gems, gems per click, pickaxe cost, robots and robot cost.
  • Use set size to, not change size by, for the click squash. Scratch restarts a when this sprite clicked script on every click, and in our test the change-size version shrank the crystal away after twenty fast clicks.
  • Check purchases with not <gems < cost>, not gems > cost. Scratch has no greater-than-or-equal block, and the > version refuses a player who has exactly enough.
  • Pay first, then raise the price. Reverse the order and the player is charged the new, higher price.
  • round (cost * 1.15) gives prices that rise about 15 percent per purchase and stay whole numbers.

What does the finished clicker game in Scratch look like?

One crystal in the middle of the stage, two shop buttons on the right, and the gem count in large numbers at the top. That is the entire screen, and it is enough.

Labelled layout of a Scratch clicker game stage: a large gems readout top left, a crystal sprite in the centre to click, and two shop buttons on the right for a pickaxe upgrade and a mining robot
Three sprites and one stage. The crystal earns, the two buttons spend, and the readout is a variable monitor switched to large readout, so it needs no code at all.

Before any blocks, here are the five variables the game needs. Make every one with For all sprites selected, because the crystal, both buttons and the stage all need to read and change the same numbers. If you have not met that choice before, our guide to making a score counter in Scratch explains exactly why it matters, and what goes wrong in clone games when it is set the other way.

VariableStarts atWhat it holds
gems0The player's money
gems per click1How many gems one click earns
pickaxe cost10Price of the next pickaxe upgrade
robots0How many mining robots the player owns
robot cost50Price of the next robot

Steps 1 to 3: sprites, variables and a clean start

  1. Add the sprites. Delete the cat. Click Choose a Sprite and add Crystal, which is in Scratch's own library with two costumes. Then add Button2 and Button3 for the shop. Rename them Crystal, Pickaxe Shop and Robot Shop, and drag the two buttons to the right side of the stage. Click the green flag: nothing happens yet, and that is correct.
  2. Make the five variables. In the Variables category, click Make a Variable five times, using the names in the table above, each one For all sprites. Untick the checkboxes for everything except gems, then right-click the gems monitor on the stage and choose large readout. Click the green flag: still nothing, but you should see a big 0 at the top of the stage.
  3. Reset everything on the green flag. Click the stage (bottom right of the editor) and build this script:
    • when green flag clicked
    • set [gems] to (0)
    • set [gems per click] to (1)
    • set [pickaxe cost] to (10)
    • set [robots] to (0)
    • set [robot cost] to (50)
    Click the green flag: the readout shows 0. This step matters more than it looks, because Scratch keeps variable values when a project is saved. Without it, a game reopened tomorrow starts with whatever gems and prices it had today.

Step 4: make the crystal earn gems

Click the Crystal sprite and give it one script:

  • when this sprite clicked
  • change [gems] by (gems per click)

Drag the round (gems per click) reporter from the Variables palette into the number slot. Do not type a 1 there. Typing a 1 works today and silently breaks the pickaxe upgrade in step 6, which is the kind of bug that makes a child think the shop code is wrong when the crystal code is.

Click the green flag, then click the crystal five times: the readout should go 1, 2, 3, 4, 5. Click the green flag again and it should drop back to 0.

Step 5: the squash effect, and the version that breaks

A click needs to feel like something. The usual trick is a quick squash: the crystal shrinks a little and springs back. Almost every first attempt looks like this:

  • change size by (-10)
  • wait (0.1) seconds
  • change size by (10)

It works perfectly when you click slowly. Click fast, the way anyone plays a clicker game, and the crystal gets smaller and smaller until it nearly disappears.

The cause is a rule hardly any tutorial mentions. In the Scratch 3.0 source code, the when this sprite clicked hat is set to restart its script if it is clicked while that script is still running. So a second click that lands during the 0.1-second wait throws away the rest of the first run, including the change size by (10) that was about to put the size back. The first click took 10 off and never returned it. The second click takes another 10.

We tested this in the Scratch 3.0 engine itself. Twenty clicks about ten a second, using the change-size version, drove the size value from 100 to below zero; on a real stage Scratch stops a sprite at a speck a few pixels across, so the crystal effectively vanishes. At about seven clicks a second it recovered every time, and around eight a second it lost some size and kept the rest. A child mashing the mouse goes well past eight.

Comparison of two Scratch click squash scripts after twenty fast clicks: with change size by minus ten the crystal shrinks smaller at every step, with set size to ninety percent it stays at one hundred percent
Same clicks, different blocks. The relative version loses ten percent on every interrupted click; the absolute version cannot drift, because it never depends on the size it started from.

The fix is to describe the target size instead of the change:

  • when this sprite clicked
  • change [gems] by (gems per click)
  • set size to (90) %
  • wait (0.1) seconds
  • set size to (100) %

Notice the order too. The gems line goes first, above the wait, so an interrupted click still pays. Put it below the wait and fast clicks earn nothing, because the restart cuts the script off before it gets there. In our test, with the gems line at the top, twenty fast clicks earned exactly twenty gems.

Click the green flag, then click the crystal as fast as you can for five seconds: the crystal should pulse and always return to its normal size, and the gems should keep pace with your clicks.

If your child got stuck at the squash bug and you are not sure how to explain it, that is exactly the moment a live teacher helps. A free trial class with a Codeyoung teacher shows you where your child is and what they are ready for next, before you commit to anything.

Book a Free Trial →

Step 6: build the upgrade shop

The pickaxe raises gems per click by one. Click the Pickaxe Shop sprite and build:

  • when this sprite clicked
  • if <not <(gems) < (pickaxe cost)>> then
    • change [gems] by ((0) - (pickaxe cost))
    • change [gems per click] by (1)
    • set [pickaxe cost] to (round ((pickaxe cost) * (1.15)))
  • else
    • switch costume to (button2-b)
    • wait (0.2) seconds
    • switch costume to (button2-a)

Two details in that script are deliberate, and both fix a real bug.

Why not <gems < cost> instead of gems > cost

The natural way to write "can I afford it" is <(gems) > (pickaxe cost)>. Try it with exactly 10 gems and a price of 10: nothing happens, because 10 is not greater than 10. The player has precisely enough and the shop refuses them. Children usually decide the shop is broken and start changing things that are fine.

Scratch's Operators category has >, < and =, and no greater-than-or-equal block. The cleanest way to say "at least" is to wrap the opposite question in not: "gems is not less than the cost" is true at 10 and above. It is also a good small logic lesson, since it is the first time many children meet a condition that is easier to state backwards.

Why pay before raising the price

The three lines inside the if run in order. If set [pickaxe cost] came first, the next line would charge the new price, so a player buying a 10-gem pickaxe would lose 12. Pay, deliver, then reprice. The (0) - (pickaxe cost) is there because Scratch has no "take away" block for variables; changing by a negative number does the same job.

The else branch flashes the button to its second costume when the player cannot afford it. It uses switch costume to rather than next costume for the same reason as the squash fix: a fast double-click restarts the script, and absolute instructions survive a restart where relative ones do not.

Click the green flag, mine 10 gems, then click the pickaxe: gems drop to 0, and each crystal click now earns 2. Click the pickaxe again with fewer than 12 gems and the button should flash.

Step 7: make prices rise with every purchase

Without price scaling, the game has a single right answer: buy pickaxes forever. Rising prices are what make the choice between pickaxe and robot interesting.

The round ((pickaxe cost) * (1.15)) line in step 6 does this. Multiplying by 1.15 makes each price about 15 percent higher than the one before, and round keeps it a whole number. Here is what that produces:

Purchase1st2nd3rd4th5th6th
Pickaxe cost101214161821
Robot cost5057667687100
Bar chart of a Scratch clicker game robot price rising after each purchase, from 50 to 57, 66, 76, 87 and 100, with the sixth bar exactly twice the length of the first
Five purchases at 15 percent each double the robot's price. That doubling is what keeps a clicker game from being solved in the first minute.

Two things in that table are worth pointing out to an older child. First, leave out round and the pickaxe costs 13.225 after two purchases and 15.208749999999998 after three, which is not a price anyone can read. Second, the robot goes from 50 to 57, not 58, even though 50 times 1.15 is 57.5 and Scratch rounds halves up. Computers store 1.15 as a binary number very slightly smaller than 1.15, so the answer comes out as 57.49999999999999 and rounds down. It is a real, harmless example of why programmers never trust a decimal to be exact.

Click the green flag and buy three pickaxes: the prices you pay should be 10, then 12, then 14.

Step 8: add an auto-mining robot

The robot is what turns a clicking game into a clicker game: gems arrive while the player does nothing. Click the Robot Shop sprite. Its buy script is the step 6 script with the names changed: check not <(gems) < (robot cost)>, pay (0) - (robot cost), change [robots] by (1), then set [robot cost] to (round ((robot cost) * (1.15))). Use button3-b and button3-a for the flash.

Then give the Robot Shop a second, separate script:

  • when green flag clicked
  • forever
    • wait (1) seconds
    • change [gems] by (robots)

It must hang from the green flag, not from when this sprite clicked. Put the forever loop in the click script and every click on the shop restarts it, so a player who buys robots quickly keeps resetting their own income.

Plenty of forum advice says a wait (1) seconds loop runs a whole frame slow every time round, which would lose about one point in thirty. We could not reproduce that in Scratch 3.0. We ran this exact loop in the Scratch 3.0 engine for five minutes, and one robot earned 297 gems in 300 seconds: about one percent slow, not three. For a clicker game that is invisible. If your child later builds something where seconds must be exact, such as a countdown, the built-in timer reporter is the precise tool, and our step-by-step Scratch timer tutorial shows how to use it.

Click the green flag, mine 50 gems and buy a robot: the gems should now rise by 1 every second without any clicking. Buy a second and they rise by 2.

Step 9: show the prices on the buttons

The player needs to see what things cost. Add this to the Pickaxe Shop:

  • when green flag clicked
  • forever
    • say (join [Pickaxe: ] (pickaxe cost))

Do the same on the Robot Shop with (join [Robot: ] (robot cost)). Leave a space after the colon inside the first slot of join, or the number sticks to the word. The speech bubble updates the instant a price changes.

If your child wants to show income as well, tick the checkbox beside robots so it appears on the stage, and right-click it to choose how it looks. A normal readout shows the name and value, a large readout shows only the value, and a slider is for numbers the player sets, which these are not.

Click the green flag: the buttons should read "Pickaxe: 10" and "Robot: 50", and change the moment you buy.

Testing checklist: four bugs and their fixes

When something goes wrong, it is almost always one of these. Read the symptom column first.

SymptomCauseFix
Crystal shrinks away with fast clickschange size by plus script restartset size to (90) % and set size to (100) %
Cannot buy with exactly enough gemsgems > costnot <(gems) < (cost)>
Upgrade costs more than the label saidPrice raised before payingPay, deliver, then reprice
Pickaxe bought but clicks still earn 1Typed 1 in the crystal's change blockUse the (gems per click) reporter

The approach that finds these fastest is to predict before testing: say out loud what the number should be after the next click, then click. A wrong prediction points straight at the line to check. Our guide to teaching kids debugging goes further with that habit.

Where to take Gem Miner next

Once the base game works, each addition is a small project of its own:

  • A record that survives a reload. Gems reset when the game reopens. Keeping a best total between players needs a cloud variable, and our guide to saving a high score in Scratch covers the rules, including why brand-new accounts cannot use one yet.
  • A third upgrade, such as a drill that adds 5 per second at a starting price of 300. It is the robot script again with different numbers, which is a good test of whether your child understood it or copied it.
  • A goal. Clicker games can run forever, but children often enjoy a finish line: wait until <(gems) > (999)> followed by a winning backdrop.

For a broader build with movement, collisions and levels, how to make a game on Scratch is the natural next tutorial.

Conclusion

A clicker game in Scratch is five variables, a crystal that earns, two shop buttons that spend, and one forever loop that pays the robots. The parts worth slowing down for are the three that look right and are not: the squash that shrinks under fast clicking because the click script restarts, the > check that refuses exact money, and the purchase that charges the new price because the lines are in the wrong order. A child who can explain why each fix works has learned more than one who simply copied a working game.

If your child enjoyed this, Codeyoung's Scratch coding classes build projects like this one with a teacher alongside, so the bugs become lessons instead of reasons to stop.

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 checked 12 November 2026: block labels from the Scratch Wiki Blocks list, Wait () Seconds and Variable pages; the restart behaviour of when this sprite clicked from the Scratch Foundation's scratch-vm source; the Crystal, Button2 and Button3 sprites from the scratch-gui sprite library file. The rapid-click and five-minute loop measurements are our own, run on the scratch-vm engine; a browser may differ slightly in timing.

Frequently Asked Questions

How do you make a clicker game in Scratch?
Make a variable for points, reset it under when green flag clicked, and add change points by 1 under when this sprite clicked on the object the player clicks. Then add a shop sprite that spends points on upgrades, and a forever loop that adds points every second for an auto-clicker.
Why does my Scratch sprite keep getting smaller when I click it fast?
Because when this sprite clicked restarts its script on every click. If the script uses change size by -10, wait, then change size by 10, a fast click restarts it before the size goes back up, so each one loses ten. Use set size to 90% and set size to 100% instead.
Why can't I buy an upgrade when I have exactly enough points?
The check probably uses points > cost, and ten is not greater than ten. Scratch has no greater-than-or-equal block, so the usual fix is not , which is true when points are equal to the cost or above it. That one change makes the exact-money purchase work.
How do you make an auto-clicker in Scratch?
Under when green flag clicked, add a forever loop holding wait 1 seconds and change points by robots, where robots is a variable counting auto-clickers bought. Keep the loop out of any when this sprite clicked script, because each click restarts that script and the loop with it.
How do you make upgrade prices go up in Scratch?
After the purchase, set the cost variable to round of cost times 1.15. Each price is then about 15 percent higher than the last. The round block keeps the price a whole number; without it the price becomes a long decimal after only two or three purchases.
What age can build a clicker game in Scratch?
Most children who have already built one simple Scratch game with a score can do the clicking and the shop at around 8 to 10. Price scaling uses multiplication by a decimal, so it usually lands better at 10 and up, or with an adult explaining the 1.15 once.

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.