local plist = game.SoundService.Folder
local song = plist[math.random(1,#plist:GetChildren())]
while true do
song:Play()
end
So what I am trying to do is make it so the songs play one after another without a specific order so people don’t hear the same song twice or more in a row. How would I do this quickly? My script only goes through one song, and I don’t know how to detect with the song is finished so I can play another.
local plist = game.SoundService.Folder:GetChildren()
-- function for randomizing a table
local function FYshuffle(t)
local j, temp
for i = #t, 1, -1 do
j = math.random(i)
temp = t[i]
t[i] = t[j]
t[j] = temp
end
end
local n = #plist + 1
local lastSongPlayed
while (#plist > 1) do -- doesn't work if there's only one song
-- if at the end of playlist, shuffle playlist and reset 'n'
if (n > #plist) then
repeat
FYshuffle(plist)
-- shuffle again if the next song is same as last song.
until (plist[1] ~= lastSongPlayed)
n = 1
end
-- play the next song and increment 'n'
lastSongPlayed = plist[n]
plist[n]:Play()
plist[n].Ended:Wait()
n = n + 1
end
It doesn’t play a song after the original. I just tested and it only plays one song and no more. There are a total of 6 songs in the playlist yet it only plays one.
Ok I think I see the issue. It works in the “Test” mode in studio but in a simulated game the .Ended event is not replicating from the server to the client.