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?
01 | function startSong() |
02 | local isStarted 1 = false |
03 | local isStarted 2 = false |
04 | local isStarted 3 = false |
05 | local isStarted 4 = false |
06 | local isStarted 5 = false |
07 |
08 | while true do |
09 | if not isStarted 1 then |
10 | game.Workspace.Feeling:Play() |
11 | isStarted 1 = true |
12 | wait( 120 ) |
13 | game.Workspace.Feeling:Stop() |
14 | isStarted 1 = false |
15 | elseif not isStarted 2 then |
Here you go, try this:
01 | local lastSong = 1 |
02 | while wait() do |
03 | repeat song = math.random( 1 , 5 ) until song~ = lastSong |
04 | lastSong = 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 ) |
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!
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:
1 | while true do |
2 | Song 1 :Play () |
3 | wait ( 120 ) |
4 | Song 1 :Stop () |
5 | Song 2 :Play () |
6 | wait ( 120 ) |
7 | Song 2 :Stop () |
8 | end |
It's because you set isStarted back to false and the condition goes back to the first song.
I suggested doing it like...
1 | local songnumber = 1 |
2 | if songnumber = = 1 |
3 | --Yada Yada |
4 | songnumber = 2 |
5 | elseif songnumber = = 2 then |
6 | -- Yada Yada |
7 | songnumber = 1 |