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

Why does my music script keep repeating the same song?

Asked by
Scenal 20
11 years ago

Hi, this is the script, and it keeps on playing the first song over and over again- I've checked if it's looped and it isn't. What's wrong?

01function startSong()
02    local isStarted1 = false
03    local isStarted2 = false
04    local isStarted3 = false
05    local isStarted4 = false
06    local isStarted5 = false
07 
08 while true do
09        if not isStarted1 then
10            game.Workspace.Feeling:Play()
11            isStarted1 = true
12            wait(120)
13            game.Workspace.Feeling:Stop()
14            isStarted1 = false
15        elseif not isStarted2 then
View all 43 lines...

4 answers

Log in to vote
1
Answered by 11 years ago

Here you go, try this:

01local lastSong=1
02while wait() do
03repeat song=math.random(1,5) until song~= lastSong
04lastSong=song;
05        if song==1 then
06            game.Workspace.Feeling:Play()
07            wait(120)
08            game.Workspace.Feeling:Stop()
09        elseif song==2 then
10            game.Workspace.Po:play()
11            wait(120)
12            game.Workspace.Po:Stop()
13       elseif song==3 then
14            game.Workspace.Demons:play()
15            wait(120)
View all 26 lines...
0
Thanks, is there anyway to stop it playing the same song twice? Scenal 20 — 11y
0
Also, when someone else joins, it repeats the script and overlaps, which makes lots of songs play at once- How do I fix this? Scenal 20 — 11y
0
You can parent the songs to the player's PlayerGui to make it play locally. TheGuyWithAShortName 673 — 11y
0
Also, I've made it so that it won't play the same song 2 times in a row. TheGuyWithAShortName 673 — 11y
Ad
Log in to vote
1
Answered by 11 years ago

It's because you are setting isStarted1 to false after it plays its 120 seconds worth of audio, which then redirects it to the same conditional path (i.e. if not isStarted1 then...)

If you want it to play one after another, cut out the lines where it sets each isStarted value to false, and paste them at the end of the loop, altogether.

Good luck; hope I could be of help! Please consider leaving an upvote!

0
This also glitches, when another person joins, it plays the song again and makes two songs overlap over eachother, how would I fix this? Scenal 20 — 11y
Log in to vote
0
Answered by
Maxomega3 106
11 years ago

Every time the loop runs, it sees that the first loop is false. The loop while loop will only repeat once it's finished.

Just do:

1while true do
2    Song1:Play ()
3    wait (120)
4    Song1:Stop ()
5    Song2:Play ()
6    wait (120)
7    Song2:Stop ()
8end
Log in to vote
0
Answered by
Bebee2 195
11 years ago

It's because you set isStarted back to false and the condition goes back to the first song.

I suggested doing it like...

1local songnumber = 1
2if songnumber == 1
3--Yada Yada
4songnumber = 2
5elseif songnumber == 2 then
6-- Yada Yada
7songnumber = 1
0
Either of anyone's scripts will work. Bebee2 195 — 11y
0
What is 'Yada Yada'? Scenal 20 — 11y

Answer this question