# Glitch when triggering sound on projectile creation

**URL:** <https://forum.makecode.com/t/glitch-when-triggering-sound-on-projectile-creation/23804>\
**Category:** Help\
**Created:** [October 31, 2023, 5:35pm UTC](https://forum.makecode.com/t/glitch-when-triggering-sound-on-projectile-creation/23804 "2023-10-31T17:35:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.holland.teals](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@john.holland.teals](https://forum.makecode.com/u/john.holland.teals)\
**Post date:** [October 31, 2023, 5:35pm UTC](https://forum.makecode.com/t/glitch-when-triggering-sound-on-projectile-creation/23804/1 "2023-10-31T17:35:22Z")

</div>

Hi, I’m helping teach Arcade.Makecode for TEALS and student found an issue. We create a game with a movable player sprite, set the A button to create projectiles from the student, and then set an “on created sprite of type projectile” to play a “pew pew” song. With this combination the projectiles momentarily appear in the center of the screen and then relocate to the correct location (where the player sprite is).

> **[testbug](https://arcade.makecode.com/S06785-93680-74701-34221)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 31, 2023, 5:40pm UTC](https://forum.makecode.com/t/glitch-when-triggering-sound-on-projectile-creation/23804/2 "2023-10-31T17:40:37Z")

</div>

This one is somewhat expected behavior; we run the ‘on sprite created’ code synchronously / before we ‘finish’ making the sprite and continue from wherever the sprite is made, because we need to be able to use it to make changes that affect the code that follows (e.g. changing the image and letting the code after see the new image). In this case, to get the behavior you want, you can change the dropdown in the `play sound` block so that it does not stop the rest of the code while the sound is running by changing it from `until done` to `in background`:

![to-in-background](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2b9a741e185e51285a8cda1fd7f2105d917b5d29.gif)

and more complicated examples (e.g. if you need to have a pause block for some reason? haven’t run into any myself) can be handled by using the timers extension with the `separately do` block

(We could consider moving the projectile logic so that the position / velocity are set before the on create runs, but that’d also have some weird behavior – e.g. if the image was changed, the projectile would be positioned incorrectly. For that reason I’d lean towards keeping as is.)

---

<div class="post-metadata">

**Author:** ![john.holland.teals](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@john.holland.teals](https://forum.makecode.com/u/john.holland.teals)\
**Post date:** [October 31, 2023, 8:47pm UTC](https://forum.makecode.com/t/glitch-when-triggering-sound-on-projectile-creation/23804/3 "2023-10-31T20:47:47Z")

</div>

Thanks, that does fix the behavior. I know there’s a lot going on behind the scenes of our makecode env. Appreciate the quick response!
