✓ Accepted answer
Here, I have a way better solution -- you don't have to delete anything!
local play = true
local debounce = false
local Songs = game.Workspace.Songs
local function songs ()
while true do
Songs.DarudeSand:Play()
wait(123)
Songs.Bangarang:Play()
wait(94)
Songs.ET:Play()
wait(119)
Songs.Poison:Play()
end
songs()
script.Parent.Parent.StarterGui.ShopAct.Frame.ImageButton.MouseButton1Click:Connect(function()
if debounce == false then
debounce = true
if play == true then
play == false
elseif play==false then
play == true
end
for i,v in pairs(Songs:GetChildren())
if v:IsA("Sound") then
if play == false then
v:Pause()
elseif play == true then
v:Resume()
end
end
end
wait(1)
debounce == false
end
end)
I simply defined a boolean value that can be set to true or false judging by the button press, a debounce is added so it isn't constantly changing the value.
Once the "if" statements decide whether to be false or true, it then does a loop of the Songs folder/model and checks if a certain member of the model (v) is a sound. Once it figures that out, it pauses or resumes it judging by whether play is false or true.
Although, if you want, I do have a huge module script that you could use to play your songs alternatively instead of ":Play()"
https://forum.scriptinghelpers.org/topic/725/cvextra-super-module-script
MODULE SCRIPT: https://www.roblox.com/library/2674126390/CVExtra-Super-Module-Script
A remade form using my script (THIS ASSUMES YOU PUT THE MODULE SCRIPT IN THE WORKSPACE):
local play = true
local debounce = false
local Songs = game.Workspace:FindFirstChild("Songs")
local CVExtra = game.Workspace:FindFirstChild("CVExtra")
local playAudio = CVExtra.playAudio
local function songs ()
while true do
playAudio(Songs.DarudeSand)
wait(0.5)
playAudio(Songs.Bangarang)
wait(0.5)
playAudio(Songs.ET)
wait(0.5)
playAudio(Songs.Poison)
end
songs()
script.Parent.Parent.StarterGui.ShopAct.Frame.ImageButton.MouseButton1Click:Connect(function()
if debounce == false then
debounce = true
if play == true then
play == false
elseif play==false then
play == true
end
for i,v in pairs(Songs:GetChildren())
if v:IsA("Sound") then
if play == false then
v:Pause()
elseif play == true then
v:Resume()
end
end
end
wait(1)
debounce == false
end
end)
Do not worry about doing a whole wait of the song's length, my module script has that all done for you, and it'll wait if the audio gets paused.
1 comment
If something may not exist, use Instance:FindFirstChild()