Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Music change when button press
- mazarianpartii
-
Scratcher
6 posts
Music change when button press
Hey, I'm making a project thats basically a website thing, it has 4 buttons on the main page and when you click them it redirects to a different page. One feature ive been tinkering with is music in the background, the Homepage has music A, the current page Im working (about) on has music B. one of my current issues is that when a different site is clicked, its supposed to loop a ne song, but the 2 songs with homepage overlap. The way the code works is that when you click the button, it broadcasts the page's event, which switches backdrop to the pages backdrop, stops all music and loops the new one, but it isn't working, and I cant find any video that explains how to code this. please help?
- dem_bot
-
Scratcher
100+ posts
Music change when button press
With broadcasts you need to be careful about what receives it. Clones will also react to it.
It would help if u share the code so we can take a look
It would help if u share the code so we can take a look
- mazarianpartii
-
Scratcher
6 posts
Music change when button press
With broadcasts you need to be careful about what receives it. Clones will also react to it.https://cdn.pixilart.com/photos/large/e1b002296167adc.png
It would help if u share the code so we can take a look
https://cdn.pixilart.com/photos/images/orginal/701abbfb6d6b098.png
- flyingpenguin321
-
Scratcher
9 posts
Music change when button press
Hello! A bit new here but I think the comment up above yours has a good answer.
It looks like the broadcast blocks are playing the new sounds and attempting to stop the previous music from playing, but if you take a look at the home page music, the forever block that it's in keeps it playing even though you may have stopped it once, if that makes sense.
So to get it to play properly you'll have to stop the forever block the other music was in.
Anyways here's a project for managing sounds that I've cooked up really quick if you'd like to reference that, though there are other ways to do it.
https://scratch.mit.edu/projects/1237500827/editor/
Hopefully that helps!
It looks like the broadcast blocks are playing the new sounds and attempting to stop the previous music from playing, but if you take a look at the home page music, the forever block that it's in keeps it playing even though you may have stopped it once, if that makes sense.
So to get it to play properly you'll have to stop the forever block the other music was in.
Anyways here's a project for managing sounds that I've cooked up really quick if you'd like to reference that, though there are other ways to do it.
https://scratch.mit.edu/projects/1237500827/editor/
Hopefully that helps!
Last edited by flyingpenguin321 (Nov. 3, 2025 22:33:07)
- mazarianpartii
-
Scratcher
6 posts
Music change when button press
Hello! A bit new here but I think the comment up above yours has a good answer.Thank you!! This is very helpful, It had made the code work, but part of the point is for the music to loop while in its web page, is that possible?
It looks like the broadcast blocks are playing the new sounds and attempting to stop the previous music from playing, but if you take a look at the home page music, the forever block that it's in keeps it playing even though you may have stopped it once, if that makes sense.
So to get it to play properly you'll have to stop the forever block the other music was in.
Anyways here's a project for managing sounds that I've cooked up really quick if you'd like to reference that, though there are other ways to do it.
https://scratch.mit.edu/projects/1237500827/editor/
Hopefully that helps!
Sorry for the late reply, i didn't get notified that the post had new responses
- flyingpenguin321
-
Scratcher
9 posts
Music change when button press
No worries! I'm glad that at least part of it is working now.
I've just realized that the other way I was thinking about wouldn't work but one way to do this might be to keep the music in its forever loop, but then use the stop other scripts block to stop it before playing the new music. But this uses the stop other scripts block so you may need to put it into its own music sprite.
I've just realized that the other way I was thinking about wouldn't work but one way to do this might be to keep the music in its forever loop, but then use the stop other scripts block to stop it before playing the new music. But this uses the stop other scripts block so you may need to put it into its own music sprite.
- Discussion Forums
- » Help with Scripts
-
» Music change when button press


