I'm not much of a scripter but i did learned how to make a music button for my background music off the wiki
local button = script.Parent
local sound = button:WaitForChild('Sound')
sound:Play()
local function onButtonClick()
if sound.IsPlaying then
button.Image = 'http://www.roblox.com/asset/?id=166376559'
sound:Stop()
else
button.Image = 'http://www.roblox.com/asset/?id=166376578'
sound:Play()
end
end
button.MouseButton1Click:connect(onButtonClick)
right now only the first 120 second sound plays but I have 2 sounds that go together but are split up into 2 parts because 120 second limit. I put 2 sounds in ImageButton called sound and sound2 now i need sound 2 to play right after sound 1 and then after sound 2 is done sound 1 plays again Would this work adding a loop:
local button = script.Parent
local sound = button:WaitForChild('Sound')
while true do
sound:Play()
wait(120)
sound2:Play()
wait(50)
end
local function onButtonClick()
if sound.IsPlaying then
button.Image = 'http://www.roblox.com/asset/?id=166376559'
sound:Stop()
else
button.Image = 'http://www.roblox.com/asset/?id=166376578'
sound:Play()
end
end
button.MouseButton1Click:connect(onButtonClick)
I don't think that's right at all because i don't know what i'm doing but i would appreciate it if someone could help me out.?

3 comments
Is there a reason you can't use one of the Sound events (e.g. Ended) that makes you write a repeat loop yourself?
pairs/next is unordered. Since the
soundsis a list and the elements have an order, you want to use ipairs.Ah good point. And I would use Ended, but I also wanted it to stop playing once the varaible shouldPlay was set to false (didn't want to "complicate" it with a BindableEvent).