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!
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)
Post the whole script.