This script I made, is used to cycle through a playlist of songs, but when it gets to song 4, it just stops and doesnt cycle through anymore.
My script -
local Sound1 = game.Workspace.Sounds.Sound1
local Sound2 = game.Workspace.Sounds.Sound2
local Sound3 = game.Workspace.Sounds.Sound3
local Sound4 = game.Workspace.Sounds.Sound4
while true do
Sound1:Play()
Sound1.Ended:Wait()
Sound2:Play()
Sound2.Ended:Wait()
Sound3:Play()
Sound3.Ended:Wait()
Sound4:Play()
wait(1)
end
Please use three backticks (```) before and after your code, and also indented neatly for readability. Here’s your code again but more readable.
local Sound1 = game.Workspace.Sounds.Sound1
local Sound2 = game.Workspace.Sounds.Sound2
local Sound3 = game.Workspace.Sounds.Sound3
local Sound4 = game.Workspace.Sounds.Sound4
while true do
Sound1:Play()
Sound1.Ended:Wait()
Sound2:Play()
Sound2.Ended:Wait()
Sound3:Play()
Sound3.Ended:Wait()
Sound4:Play()
wait(1)
end
Here are the changes I would make.
Use an array to play sounds instead of just referencing them all. This means that you can add as many songs as you want later.
Iterate through the array in a while true do loop.
Use task.wait() instead of wait(1)
Here’s that in action:
local soundIds = {sound1, sound2, sound3, sound4}
local soundplayer = Instance.new("Sound")
while true do
for i,v in soundIds do
soundplayer.SoundId = v
soundplayer:Play()
soundPlayer.Ended:Wait()
end
end
Be sure to replace soundIds with the sound IDs of your sounds.
Also, it’s better to have 1 sound object and change the soundId instead of having multiple sound objects as sound objects can be quite laggy.