Script to Kill a Player
Green highlight

Write a simple game script in Scratch that causes a player's character to lose all health, play a safe 'game over' animation, and respawn.

Orange shooting star
Download Guide
Collect Badge
Background blob
Challenge Image
Skill Badge
Table of contents

Step-by-step guide to Script to Kill a Player

What you need
A 'game over' costume for the player sprite, a game over sound (optional), enemy sprite, player sprite, scratch editor open

Step 1

Open Scratch and start a new project.

Step 2

Choose or draw the sprite you want to be the player.

Step 3

Move the player sprite to the exact spot where you want it to come back after a game over and remember the x and y numbers.

Step 4

Make a new variable named health and set it to be for this sprite only.

Step 5

Add a "when green flag clicked" script to the player sprite.

Step 6

Under that "when green flag clicked" add blocks to set health to 100 and to go to the spawn x y position you remembered.

Step 7

Add a forever loop under the green flag script and inside it put an if block that checks "touching [enemy]?".

Step 8

Inside that if block add a block to set health to 0 and then add a block to broadcast "gameOver".

Step 9

Make a "when I receive [gameOver]" script on the player that switches to the game over costume then plays the game over sound until done then goes to the spawn x y and sets health back to 100 and finally switches back to the normal costume.

Step 10

Test your game by clicking the green flag and causing the player to touch the enemy to see health go to 0 play the safe game over animation and respawn and then share your finished creation on DIY.org.

Final steps

You're almost there! Complete all the steps, bring your creation to life, post it, and conquer the challenge!

Complete & Share
Challenge badge placeholder
Challenge badge

Help!?

What can I use if I can't find an 'enemy' sprite or a game over sound in Scratch?

Use any built-in sprite (for example 'Ghost' or 'Ball') and either pick a sound like 'pop' from the Sounds tab or record your own, then change the touching [enemy]? block and the 'play sound (game over) until done' block to the names you chose.

My player doesn't respawn or play the game over animation when it touches the enemy—what should I check?

Make sure the 'set health to 0' and 'broadcast gameOver' blocks are inside the if touching [enemy]? in the forever loop, the variable 'health' was created 'for this sprite only', the broadcast name exactly matches the 'when I receive [gameOver]' script on the player, and the 'go to x y' uses the exact spawn x and y you recorded.

How can I make this activity easier for younger kids or harder for older kids?

For younger kids, replace the health variable with a simple 'lives' variable set to 3 and broadcast gameOver only when lives = 0, while older kids can use 'change health by -20' on touch, add a visible health bar sprite that resizes, and implement temporary invincibility after respawn.

What are some ways to extend or personalize the game before sharing it on DIY.org?

Add a score variable, multiple enemy sprites with different damage values and costumes, an animated game over backdrop and custom sound in the 'when I receive [gameOver]' script, or create power-ups that change the player's costume and health behavior before sharing.

Watch videos on how to Script to Kill a Player

Here at SafeTube, we're on a mission to create a safer and more delightful internet. 😊

How To Make A Game - Step By Step Tutorial [1]

4 Videos

Facts about game programming with Scratch

🔁 "Respawn" means a player returns to play after being defeated; many games use checkpoints so you restart nearby instead of from the very beginning.

🧩 Scratch uses block-based, event-driven coding — you can broadcast messages (like "playerDied") to play an animation and reset health safely.

🐱 Scratch's default sprite is the orange "Scratch Cat" — it's the playful mascot kids often start coding with.

🎮 The idea of "hit points" came from tabletop role-playing games and is now a core way video games track a character's health.

🎬 The phrase "Game over" became famous in early arcade games, but friendly "game over" animations (like a gentle fade or sad wave) keep games fun for kids.

How do I make a Scratch script that makes the player's character lose all health, play a safe 'game over' animation, and respawn?

To make this in Scratch, create a 'health' variable and set it to the max at start. When a hit occurs, use 'set health to 0' or 'change health by -health', then broadcast 'game over' and switch to a gentle game-over costume or play an animation. Stop player controls, play a short sound, wait 2–3 seconds, then reset health, move the sprite to a respawn position, and broadcast 'respawn' to re-enable controls.

What materials and tools do I need to build a script in Scratch that reduces a player's health to zero, shows a gentle 'game over', and respawns them?

You need a computer or tablet with internet (or the offline Scratch editor), a Scratch 3.0 account or editor, and a project with a player sprite. Add costumes for the game-over animation and respawn, simple sounds, and a 'health' variable. Optional: keyboard/gamepad for testing, pen and paper for planning, and adult help for younger kids.

What ages is this Scratch lesson suitable for?

Scratch projects like this work well for children about 8–14 years old. Younger kids (5–7) can participate with adult guidance for block placement and testing. Teens can add features like health bars, invincibility frames, or multiple lives. Also teach debugging and problem-solving to build confidence and coding skills.

Are there safety tips or best practices when creating a 'game over and respawn' script in Scratch?

Keep animations and language non-graphic and friendly: use 'game over' screens, cartoon effects, or 'try again' messages. Teach kids to separate in-game defeat from real-life harm. For shared projects, remove player names and avoid realistic violence. Supervise younger children, review any comments, and emphasize learning, debugging, and resilience over violent wording.
DIY Yeti Character
Join Frame
Flying Text Box

One subscription, many ways to play and learn.

Try for free

Only $6.99 after trial. No credit card required

Script to Kill a Player. Activities for Kids.