# Help! player characters keep spawning in!

**URL:** <https://forum.makecode.com/t/help-player-characters-keep-spawning-in/46627>\
**Category:** Help\
**Created:** [October 24, 2026, 3:30am UTC](https://forum.makecode.com/t/help-player-characters-keep-spawning-in/46627 "2026-10-24T03:30:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/toby/32/31659_2.png) [@Toby](https://forum.makecode.com/u/Toby)\
**Post date:** [October 24, 2026, 3:30am UTC](https://forum.makecode.com/t/help-player-characters-keep-spawning-in/46627/1 "2026-10-24T03:30:42Z")

</div>

Working on a world selection screen but the game keeps on spawning player characters over and over again! it always happens when i run the command anywhere but “on game start” (ft my wonderful placeholders :3

> **[soda game](https://arcade.makecode.com/S97252-17125-76338-71115)**
>
> tralala

---

<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 24, 2026, 8:29pm UTC](https://forum.makecode.com/t/help-player-characters-keep-spawning-in/46627/2 "2026-10-24T20:29:27Z")

</div>

If you click the menu button and then click on the “show stats” button, you can see that the number of sprites in the project just keeps going up and up forever:

 ![Screenshot 2026-10-24 at 10.55.25 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/9/d923faae89f4405e78767f669daeb1aa22d4a622.png)  
 ![Screenshot 2026-10-24 at 10.55.38 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/3/4/349a8fa01f770f79bb8dc5f0d8f183cf9f891ff3.png)  
This is because the “On Game Update” loop runs every time the screen updates, which is a lot. It’s basically like a forever loop. Instead of putting your player character creation in a forever loop, which is causing the player to be created over and over and over again, you should run the code in that On Game Update only when the level changes. The solution I like best is putting the code into a function and running that function whenever you change the level, like this:  
 ![Screenshot 2026-10-24 at 11.04.18 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/e/8/e82a777e9f47a7aebc0254cc2c28f719809ad8ee.png)  
Now I see that you also have another forever loop running very similar code, so I’m going to move all that into this function as well. Here’s my version of your project:

> **[soda game](https://arcade.makecode.com/S99009-58970-80551-84865)**
>
> tralala
