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

Why does my music script keep repeating music when people join?

Asked by
Scenal 20
10 years ago

Hi, when people join my place, the music keeps playing from my script.

Here is the script:

while true do

game.Workspace.song1name:Play()

wait(song1length)

game.Workspace.song2name:Play()

wait(song2length)

end

It is a LOCAL Script, and I've tried putting it in many places such as Workspace and StarterGUI, but everytime it keeps repeating. I've tried a normal script too.

1 answer

Log in to vote
2
Answered by 10 years ago

You need to see if the sound is started, otherwise it spams the sound, try something like this:

function startSong()
    local isStarted1 = false
    local isStarted2 = false
    while true do
        if not isStarted1 then
            game.Workspace.song1name:Play()
            isStarted1 = true
            wait(song1length)
            game.Workspace.song1name:Stop()
            isStarted1 = false
        elseif not isStarted 2 then
            game.Workspace.song1name:play()
            isStarted2 = true
            wait(song2length)
            game.Workspace.song2name:Stop()
            isStarted2 = false
        end
        wait(1) -- Wait 1 second before relooping again, or it will crash for StackOverflow (infinite loop)
    end
end
startSong()
0
Thanks so much. Scenal 20 — 10y
1
You can now upvote, that was a good question =) alessandro112 161 — 10y
1
Thanks :D Scenal 20 — 10y
0
Does it have to be in a specific place? Scenal 20 — 10y
View all comments (5 more)
0
StarterGui alessandro112 161 — 10y
0
Ok, if I add more music, do I just add another isStarted3 then copy the 'ELSE IF NOT' section of the script? Scenal 20 — 10y
0
Yes =) alessandro112 161 — 10y
0
Why does it keep repeating the first song over and over again? Scenal 20 — 10y
0
in each statement stop all the music alessandro112 161 — 10y
Ad

Answer this question