# Why is the music lagging? Plz help

**URL:** <https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612>\
**Category:** Help\
**Tags:** game\
**Created:** [May 16, 2022, 5:42pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612 "2022-05-16T17:42:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PrinceDaBezt123](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/princedabezt123/32/6280_2.png) [@PrinceDaBezt123](https://forum.makecode.com/u/PrinceDaBezt123)\
**Post date:** [May 16, 2022, 5:42pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/1 "2022-05-16T17:42:48Z")

</div>

Hey everyone, so here’s a game I made recently. Press A to enter buildings. However, each setting has a different piece of music, but it doesn’t change right away until the prevoius piece of music is FINISHED playing. Anyone know how to change that? Thanks so much ~

> **[Your Boy Group](https://arcade.makecode.com/S44222-93919-94103-41234)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![DataZero](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/datazero/32/6206_2.png) [@DataZero](https://forum.makecode.com/u/DataZero)\
**Post date:** [May 16, 2022, 9:01pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/2 "2022-05-16T21:01:12Z")

</div>

This happened to me to and it also lagged my game, im not sure why

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [May 18, 2022, 11:44pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/3 "2022-05-18T23:44:56Z")

</div>

I am not very familiar with sound/melody, but hope this can help, before experts of this field have time. Then I tried your project and studied play/stop melody a little.

- Every call “play melody()” return and go to next codes until it play complete, in other words, like “play until done”.
- The “stop all sound” can work immediately.
- But the next “play melody” in the forever did work, after the stop(), which is belong to last building/lobby still.

So we need a mechinism that check the building/lobby change, after each one melody playing. Quit out the forever, if changed. And then enter again with new building melody list.

So I changed following:

- define melodies list and BPM in each building/lobby entering blocks
- in the forever, save current building/lobby (the path in your case)
- check it changing after each playing.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4515965772054a23876ca880843c78a016c83c24.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/7d9bc2b170093fc502e7c8de85ff16e130468f33.png)

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

> **[Your Boy Group](https://arcade.makecode.com/43831-97484-96198-28609)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![PrinceDaBezt123](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/princedabezt123/32/6280_2.png) [@PrinceDaBezt123](https://forum.makecode.com/u/PrinceDaBezt123)\
**Post date:** [May 19, 2022, 12:39am UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/4 "2022-05-19T00:39:10Z")

</div>

Thanks so much for all your hard work @AqeeAqee! You really helped me out here a lot. You guys are the best!

---

<div class="post-metadata">

**Author:** ![IvanPoon](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/ivanpoon/32/6232_2.png) [@IvanPoon](https://forum.makecode.com/u/IvanPoon)\
**Post date:** [May 19, 2022, 6:33pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/5 "2022-05-19T18:33:09Z")

</div>

check the code again, that might help… will it did help on mind

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [May 19, 2022, 6:33pm UTC](https://forum.makecode.com/t/why-is-the-music-lagging-plz-help/13612/6 "2022-05-19T18:33:33Z")

</div>

Welcome!  
Very happy that clear some barries of you guys as far as I can, and looking forwad for your imaginative games!
