How to make a timer in scratch

New Page

How to play a timer in Scratch (beginners 8+) | Juni learning

Inicio » Artículos » Starting a stopwatch in Scratch (beginners 8+) | Juni learning


How to play a timer in Scratch (beginners 8+) | Juni learning


a timer illustration that represents the timer in scratch games

How to empezar

This artículo will teach you how to start a timer in Scratch, the language of free visual programming. The script that describes aquí encaja perfectly en cualquier proyecto de codificación de Scratch, ¡especialmente en los juegos!

The clocks are excellent for the beginner Scratchers that can be a lot easier to tackle than more interesting Scratch games or projects.


Para seguir, asegúrese de seguir primero estos pasos:

  1. Conviértase en un nuevo Scratcher creando una cuenta en el site web de Scratch,
  2. Start with a new game project or create a simple game project with our beginner’s guide to Scratch games tutorial.

Why use timers?

Timers are a simple way to make any type of game more engaging and fun to play. They’re not terribly difficult to code, and they can add a ton of fun when implemented correctly! The main function of a timer is to add bets to your game. If the player runs out of time while playing, he loses!

This same idea can be used in tons of different ways. Players can try to get as many points as possible before they run out of time, or try to solve a difficult puzzle before they run out of time. Due to their flexibility, timers are present in some of the most popular games, from Fortnite to Super Mario. They are also indispensable in Scratch projects, such as our game Scratch Pearl Collector.

How to Code a Scratch Countdown Timer

In order to create a timer in Scratch, we will need to use a variable. The Scratch Wiki has a great introduction to variables. Check it out if you’re not sure what they are!

After refreshing yourself on the variables, create a new variable by going to the Variables section of the block menu. The Create Variable button will take you to a new screen to create your new variable.

The Create Variable button in Scratch under the Variable Blocks section.

Click “Create variable” in the Variables section to create a new variable.

You will be prompted to enter a new variable name. The name you put here will be the name that will show up on your game screen, so make it descriptive! We decided to name our timer variable Time Remaining. Also, make sure the For All Sprites button is clicked! This will ensure that all sprites in your project can access the timer variable.

the New Variable screen in Scratch to create a new variable

Name your variable something descriptive, and check “For all sprites.”

Finally, after creating this variable, check the box to the left of the variable in the block menu. This tells Scratch to display the variable on the stage, making it visible to the player.

button to make the variable visible to the player on the Scratch stage

Make sure to check the checkbox next to your new variable to make it visible on the stage.

Now that we’ve created our timer variable, let’s write code to make it a functional timer! We can write this code on any sprite — it won’t make a big difference.

the coding block script to create a timer in Scratch

Write this code script for any sprite to set a timer for your Scratch game.

This is a simple Scratch script that creates a functional timer. Here’s a simple explanation of how this works:  

  1. The timer begins running when the green flag is clicked.
  2. The “Time Remaining” variable keeps track of the amount of time you have left. It starts at 60 seconds, and resets back to 60 whenever the green flag is clicked. You can customize this timer to the number of seconds you’d like! Simply change the 60 to your desired amount of time.
  3. The actual timer runs in a loop. It repeats 60 times, because we decided that our timer would last for 60 seconds.
  4. Inside of the loop, we wait 1 second, then change our variable by -1. This means that every second, the Time Remaining variable decreases by one.
  5. After repeating 60 times, the Time Remaining variable is equal to 0! This means that we are out of time, and the loop finished.
  6. When the timer ends, the script moves on to say Game Over for 2 seconds.
  7. Finally, the stop all block brings the rest of your game to a halt when time runs out.

That’s pretty simple, right? We set a variable to 60, then decrease it until the value of the timer reaches zero. Once that happens, the timer stops and time is up!

Test It Out Yourself

In our step-by-step article on how to make a game on Scratch, we made a simple game about collecting pearls. We can add a timer to this in order to make it more engaging!

Check out our Advanced Pearl Collector game project to see what it looks like with a timer. Play the game and see how much a timer adds to it!

an advanced scratch game with a timer function

Our advanced mermaid game is a good example of how timers can be added to Scratch games.

A Different Timer: The Built-in Scratch Timer

In addition to the script we just wrote, Scratch also offers a built-in timer variable under the Sensing tab.

However, this timer behaves rather strangely — it’s not usually what we want to use for our games. Instead of a countdown timer like above, the built-in Timer block acts like a stopwatch. It can be used to keep track of how long the game has been running for, and is super accurate!

The way the timer works can be confusing. It begins at 0, and starts counting upwards as soon as you open your Scratch project. To see this timer displayed on your screen, navigate to the Sensing category in the block menu and check the box next to the timer variable. Now, it should show up in the stage next to the other variables in your project.

the built-in Scratch timer code block

Find the timer variable in the Sensing category, and check the box to add it to your stage.

The timer reset block will reset the timer to 0 seconds. To keep track of the player’s playtime, we reset the timer to 0 when the green flag is clicked.

when green flag clicked and reset timer Scratch Coding Blocks

This script lets you use the built-in Scratch timer as a stopwatch in projects.

Now we can use this timer to know exactly how long the player has been playing the game! Although it may not be as useful as our countdown script, it still has informative and creative applications in Scratch projects.

What’s Next: More Scratch Tutorials

Adding a timer is a great bonus feature to add to any type of game! This adds an extra layer of challenge for players to test their skills and immerse themselves even more.

Other ways to make your games more fun is to add more mechanics or improve the ones you already have. Check out these tutorials to spice up your projects:

  • How to Create a Simple Game in Scratch
  • How to do a Scratch sprite jump (another essential game mechanic)
  • How to make Scratch sprites move smoothly (a better way to move)
  • How to Create Game Levels in Scratch

Plus, stay tuned for our step-by-step Scratch coding tutorials on how to create specific types of games in Scratch.

Scratch coding lessons for kids

Juni Learning offers project-based Scratch coding lessons for kids ages 8-11 to start coding. Our Scratch program prepares students to fully master the Scratch environment and prepares them to progress in coding with more advanced text-based coding languages ​​like Python.

A Juni coding instructor teaching Scratch coding.

A Juni instructor teaches Scratch to a student.

  • Game Superstar (Level 1 Scratch Course): Introduces computer basics and teaches students how to create and design their own Scratch games.
  • Game Master (Scratch Level 2 course): Covers more complex concepts like nested loops, complex conditions, cloning and more in preparation for learning more advanced coding languages.

Check out our online courses for kids coding or contact our admissions team to find out which course is best for your student!

This article originally appeared on


Video How to make a timer in scratch

Related Posts

How to add seo keywords in wordpress

Contents1 Cómo agregar palabras clave de SEO en WordPress (aumentar el CTR y las clasificaciones)1.1 Post Title1.2 Headline1.3 Header Tags1.4 Introduction and Conclusion1.5 Body Copy1.6 URL1.7 Meta…

How to embed google calendar into wordpress

Contents1 How to Add a Google Calendar in WordPress (Step by Step)2 Add a Google calendar to your website3 calendario de Google3.1 Versatile plans and pricing4 Video…

How to change the logo in wordpress

Contents1 How to Add a Custom Logo to Your Site Header2 Site Logo2.1 Planes y precios versátiles3 Add, remove or edit a custom logo4 Video How to…

How to add a popup on wordpress

Contents1 Easily create a WordPress emergent form (2 forms)1.1 ¿Por qué usar un formulario emergente de WordPress?1.2 Método #1: Crear un formulario emergente con OptinMonster + WPForms1.3…

How to roll back wordpress version

Contents1 How to Revert WordPress: Undo WordPress Updates (Easy Way)2 How to Downgrade WordPress & Roll Back to a Previous Version2.1 1. A WordPress update included significant changes…

How to rollback wordpress version

Contents1 How to Downgrade WordPress and Revert to an Older Version1.1 1. A WordPress update included significant changes that are not compatible with your theme or plugins1.2…