Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to stop all audio from playing?

Asked by 10 years ago

So, I have a list of songs, and when you click on their button, their respecting song plays. How can I use a stop button to stop audio from playing WITHOUT wasting tons of code space?

function onButtonClicked()
    script.Parent.Parent.Audio1:Stop()
    script.Parent.Parent.Status.Text = "Stopped"
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

You can ignore the text part. As you can see, I only have one audio, but once the library becomes bigger...

function onButtonClicked()
    script.Parent.Parent.Audio1:Stop()
    script.Parent.Parent.Audio2:Stop()
    script.Parent.Parent.Audio3:Stop()
    -- AND SO ON...
    script.Parent.Parent.Status.Text = "Stopped"
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

How can I achieve this same effect without wasting code space? If there is an alternate way to stop the audio currently playing, please tell me. Thanks!

2 answers

Log in to vote
1
Answered by 10 years ago

This only works if all the sounds are in something and there are nothing but sounds. You can add a line or two to check if it's a sound if you want.

function onButtonClicked()
    for k, v in pairs(script.Parent.Parent:GetChildren() do
        v:Stop()
    end
    script.Parent.Parent.Status.Text = "Stopped"
end
script.Parent.MouseButton1Click:connect(onButtonClicked)
0
Thanks! Also, a follow-up question: how can I make it so that people would have to stop the song (via the Stop button) before playing another song (via clicking a song button)? IcyArticunoX 355 — 10y
0
Nevermind, I figured it out. IcyArticunoX 355 — 10y
Ad
Log in to vote
0
Answered by
xp3000 0
10 years ago

Post the whole script.

0
That was the entire script for the Stop button. It's supposed to stop the music currently playing. I'm not sure if there is anything of relevancy in the other scripts for the song buttons (which just play music when clicked on). IcyArticunoX 355 — 10y

Answer this question