So basically I have this game round script that loops and I'm trying to make it choose a random song for the intermission. The problem is that the script chooses a song then automatically chooses another one without going through the round.
Here is the script:
local replicatedstorage = game:GetService("ReplicatedStorage") local status = replicatedstorage:WaitForChild("StatusValue") while true do -- Intermission for i = 30,0,-1 do status.Value = "INTERMISSION: "..i wait(1) Song = Instance.new("Sound") Song.Parent = workspace Song.Volume = 1 Song.Looped = false Assets = {274504661,263966756,346191865} for _, asset in ipairs(Assets) do game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset) end Song.SoundId = "http://www.roblox.com/asset/?id=" ..Assets[math.random(1,#Assets)] Song:Play() end -- Round for i = 100,0,-1 do status.Value = "TIME LEFT: "..i wait(1) end status.Value = "GAME OVER" wait(1) end
I see your issues. You have a the sound, in a for loop, inside of a while loop. You never closed line 6 (or line 14) until line 19. That means each time the loop goes through, it'll run the code again. Since I can't remember the exact rule for 'end', I can't tell you which for loop it's in. But, I recommend putting line 17-19, and move it to line 20, where it's outside of those loops.