# Game over win is giving an error

**URL:** <https://forum.makecode.com/t/game-over-win-is-giving-an-error/39866>\
**Category:** Help\
**Created:** [October 20, 2025, 1:07am UTC](https://forum.makecode.com/t/game-over-win-is-giving-an-error/39866 "2025-10-20T01:07:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.j](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@jacob.j](https://forum.makecode.com/u/jacob.j)\
**Post date:** [October 20, 2025, 1:07am UTC](https://forum.makecode.com/t/game-over-win-is-giving-an-error/39866/1 "2025-10-20T01:07:31Z")

</div>

Hi everyone,

I’m currently making a game in MakeCode Arcade, and I’m running into a weird issue with sprite flags. I have some logic that updates sprite flags based on certain conditions.

Here’s what I noticed:

- When I use **`on game update`** , everything works fine—even when I trigger

```auto
mp.gameOverPlayerWin(mp.playerSelector(mp.PlayerNumber.One))

```

OR

```auto
game.gameOver(true)

```

- But when I use a **`forever`** loop, I get this error:

I made a couple of example projects:

- **Forever function example (errors when pressing A):** [LINK](https://makecode.com/_CtgcEwVCgMMk)

- **On game update example (works fine):** [LINK](https://makecode.com/_3w1TxMfWR9yc)

In the forever example, clicking A is supposed to run `game.over(player 1 wins)`, but it fails with the error above. In the on-game update example, it works perfectly.

I’m wondering why using a **forever loop with a pause** causes this error, but using **on game update every 100 ms** does not.

Any ideas on how to fix this or why it’s happening?

Thanks!

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [October 20, 2025, 5:44pm UTC](https://forum.makecode.com/t/game-over-win-is-giving-an-error/39866/2 "2025-10-20T17:44:46Z")

</div>

This is happening because the Game Over essentially deletes everything when it runs (not really, but that’s a good enough explanation).  
When it deletes everything, it basically removes the thing that restarts forever loops, but if the loop is already running, it continues running until it is done. So you lose the game, but the pause block in the forever loop is running, then after the pause block you code tries to do something to those sprites, but those sprites don’t exist after the game over block ran, so the game errors.  
This doesn’t happen with On Game Update blocks because the game over deleted the thing that restarts them, so even after the delay has passed, the code inside the On Game Update doesn’t run.

Here is a simple fix for your Forever code:

 ![IMG_0599](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/f/e/feb60a6d828da43d94f47aea5fd903f97a6aad30.jpeg)

---

<div class="post-metadata">

**Author:** ![jacob.j](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@jacob.j](https://forum.makecode.com/u/jacob.j)\
**Post date:** [October 22, 2025, 5:41pm UTC](https://forum.makecode.com/t/game-over-win-is-giving-an-error/39866/3 "2025-10-22T17:41:40Z")

</div>

Thanks
