how to make music play and stop when clicking a sprite

id: 387663

category: Help with Scripts

posts: 30

BroOn4tn1t BroOn4tn1t loading
Hi i'm trying to know how to make music stop and play when I click a sprite? Can someone help? Thanks!
xMystic416 xMystic416 loading
when this sprite clicked
broadcast [ music]
when I receive [  music]
if <[music] = [off]> then


set [ music] to [on]
play sound [ v] until done
else
set [ music] to [off]
stop all sounds
end
for the stop all sounds you can also switch it with the
set volume to (0) %
if it doesn't work
BroOn4tn1t BroOn4tn1t loading
ok thanks ill try it
BroOn4tn1t BroOn4tn1t loading
wait I can't find the “set music to on” block
BroOn4tn1t BroOn4tn1t loading
it did not work
mstone326 mstone326 loading

BroOn4tn1t wrote:

wait I can't find the “set music to on” block

The set music to block is a variable. You have to go to variables and then create a variable called music. A variable can be named anything, always best to name them something that is relevant as in this case.

Try again, the above script should work after you create the variable.
BroOn4tn1t BroOn4tn1t loading
ok thanks mstone326
BroOn4tn1t BroOn4tn1t loading
when i click the sprite it just restarts the song
xMystic416 xMystic416 loading

BroOn4tn1t wrote:

when i click the sprite it just restarts the song
Can you share it so I can see what is wrong with the script?
BroOn4tn1t BroOn4tn1t loading
yeet
the script is on the play/stop music here sprite
how do you pick the song?
whistle46 whistle46 loading
when green flag clicked
play sound [ v] until done
pen up
hmm maybe
when green flag clicked
forever

end
play sound [ v]
when this sprite clicked
stop all sounds
BroOn4tn1t BroOn4tn1t loading

AmazingKeller wrote:

hmm maybe
when green flag clicked
forever

end
play sound [ v]
when this sprite clicked
stop all sounds
that wont work since its a forever loop it will play forever
RebeccaKi RebeccaKi loading
how do you do the thing where ok so it plays music and then when you click another sprite the music stops playing im trying to make a game
lion334 lion334 loading
Guys stop posting here I think it's already solved.
And this Post is 2 years old.
Conduit7 Conduit7 loading

BroOn4tn1t wrote:

Hi i'm trying to know how to make music stop and play when I click a sprite? Can someone help? Thanks!
okay so just use this code:
when green flag clicked
set [isMuted? v] to (0)
forever
play sound [music v] until done
end

when this sprite clicked
if <(isMuted?) = (0)> then
set [isMuted? v] to (1)
set volume to (0) %


else
set [isMuted? v] to (0)
set volume to (100) %
end
Conduit7 Conduit7 loading

RebeccaKi wrote:

how do you do the thing where ok so it plays music and then when you click another sprite the music stops playing im trying to make a game
just use the same code i already put up lol
BroOn4tn1t BroOn4tn1t loading

Conduit7 wrote:

RebeccaKi wrote:

how do you do the thing where ok so it plays music and then when you click another sprite the music stops playing im trying to make a game
just use the same code i already put up lol
this has been already solved dude please stop posting on this
PCK_Gamer PCK_Gamer loading
when this sprite clicked
if <(volume) = [0]> then
set volume to (100) %
else
set volume to (0) %
end
when green flag clicked
repeat until <>
play sound [Rick astley - Never gonna give you up.MP3 v] until done
end
FinalDFan FinalDFan loading
I'm trying to make a game, and what's supposed to happen is that when a sprite is clicked, the music is supposed to sop permanently. But no matter how hard I try, I just can't seem to figure out how to do it. What should I do?
cIoudyness cIoudyness loading

FinalDFan wrote:

I'm trying to make a game, and what's supposed to happen is that when a sprite is clicked, the music is supposed to sop permanently. But no matter how hard I try, I just can't seem to figure out how to do it. What should I do?
next time create a new topic for your request. reusing old topics is necroposting and a little bit frowned upon.

you can try a repeat until touching mouse and mouse down: play sound or a when sprite clicked: set volume to 0
Linas-T Linas-T loading

xMystic416 wrote:

when this sprite clicked
broadcast [ music]
when I receive [  music]
if <[music] = [off]> then


set [ music] to [on]
play sound [ v] until done
else
set [ music] to [off]
stop all sounds
end
for the stop all sounds you can also switch it with the
set volume to (0) %
if it doesn't work

xMystic416 wrote:

when this sprite clicked
broadcast [ music]
when I receive [  music]
if <[music] = [off]> then


set [ music] to [on]
play sound [ v] until done
else
set [ music] to [off]
stop all sounds
end
for the stop all sounds you can also switch it with the
set volume to (0) %
if it doesn't work
It doesn't work?
I need help with making it where if I click on a sprite it stops and when I click it again I need it to turn back on. If you help you get mentioned in my game
housemuseum housemuseum loading

Linas-T wrote:

xMystic416 wrote:

when this sprite clicked
broadcast [ music]
when I receive [  music]
if <[music] = [off]> then


set [ music] to [on]
play sound [ v] until done
else
set [ music] to [off]
stop all sounds
end
for the stop all sounds you can also switch it with the
set volume to (0) %
if it doesn't work

xMystic416 wrote:

when this sprite clicked
broadcast [ music]
when I receive [  music]
if <[music] = [off]> then


set [ music] to [on]
play sound [ v] until done
else
set [ music] to [off]
stop all sounds
end
for the stop all sounds you can also switch it with the
set volume to (0) %
if it doesn't work
It doesn't work?
and

CreamyJusticeOG wrote:

I need help with making it where if I click on a sprite it stops and when I click it again I need it to turn back on. If you help you get mentioned in my game
you guys are necroposting and it would make better sense to create a brand new topic.
Hello Guys i am making a Simulator game where if you click on a sprite called “Shop” then it will make the background music for outside then stop but when you exit then the shop music will stop and here is the script im using
when this sprite clicked
broadcast [ v]

when I receive [ v]
forever
play sound [ v] until done
end

BroOn4tn1t wrote:

when i click the sprite it just restarts the song
when green flag clicked
forever
if <(music) = [on]> then
set volume to (100) %


else
set volume to (0) %

when green flag clicked
forever
play sound [ v] until done
end

when green flag clicked
forever
if <<mouse down?> and <touching [mouse pointer v] ?>> then
if <(music) = [on]> then
set [music v] to [off]



else
set [music v] to [on]
end
end
end
Malicondi Malicondi loading
Please stop necroposting, this topic is several years old and is solved.