# Spties will not destroy on command

**URL:** <https://forum.makecode.com/t/spties-will-not-destroy-on-command/23155>\
**Category:** Help\
**Tags:** game\
**Created:** [October 9, 2023, 4:22pm UTC](https://forum.makecode.com/t/spties-will-not-destroy-on-command/23155 "2023-10-09T16:22:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unripeegg](https://avatars.discourse-cdn.com/v4/letter/u/5daacb/32.png) [@Unripeegg](https://forum.makecode.com/u/Unripeegg)\
**Post date:** [October 9, 2023, 4:22pm UTC](https://forum.makecode.com/t/spties-will-not-destroy-on-command/23155/1 "2023-10-09T16:22:36Z")

</div>

my game has a menu that has multiple pages to it, and all the pages but page 1s icons will not ‘destroy’. i have a function that destroys the sprites for each page, but when debugging i goudn that it does not destroy the sprite. the function is still run through when the command is given. does anyone have any alternitives to ‘sprites.destroy’ or know how to fix the issue?

link to game - [https://arcade.makecode.com/S39932-29147-38691-80836](https://arcade.makecode.com/S39932-29147-38691-80836)

---

<div class="post-metadata">

**Author:** ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)\
**Post date:** [October 9, 2023, 10:06pm UTC](https://forum.makecode.com/t/spties-will-not-destroy-on-command/23155/2 "2023-10-09T22:06:23Z")

</div>

Nice work, @Unripeegg! A humongous game with 7597 LOC!!!

Page 1 of the menu is closed with sprites removed, since its icons are declared ahead and outside of the function, and of global scope:

 ![correct](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/04808e5409f75ad52c5908f191197732db1fe789.png)

For the other pages, the icons are declared inside their functions, hence their scope is for the duration of the functions where the sprites are created only, and when later attempted destroyed in other functions, the sprites are no longer referenced and the _destroy()_ function cannot find and destroy them:

 ![incorrect](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/ad29c5ce8683c3926fef30ff8a8a861b9405022d.png)

Here is a version where also page 2 of the menu should work/close:

> **[splatoon locker picrew](https://arcade.makecode.com/81152-75745-93989-95353)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.
