Hey guys, Nik1080 here with another question!
So, a recently I constructed a basic music "playlist" loop:
local Sound1 = game.Workspace.Sound1
local Sound2 = game.Workspace.Sound2
local Sound3 = game.Workspace.Sound3
local Sound4 = game.Workspace.Sound4
local Sound5 = game.Workspace.Sound5
local Sound6 = game.Workspace.Sound6
local Sound7 = game.Workspace.Sound7
Assets = {346073558,183479225,167337732,175755911,199372537,247303851,342274063}
for _, asset in ipairs(Assets) do
game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
end
while true do
Sound1:Play()
wait (110) -- Note the all the waits are one second longer than the audio file
Sound2:Play()
wait(120)
Sound3:Play()
wait(114)
Sound4:Play()
wait(100)
Sound5:Play()
wait(104)
Sound6:Play()
wait(120)
Sound7:Play()
wait(120)
end
My only problem is that it gets repetitive, in the way that the order is always the same. (Note that in the end I will most likely have more) My question is, is there a way to randomize the order in which the songs are played while waiting the proper amount of time?

5 comments
You could use the math.random function, and have the returned number retrieve the position asset in the table. "local Song = tbl[math.random(1, #tbl)]"
but what about the wait? I dont think you can use those in math.random
No, you can't, but that's not what I mean w/ my comment. :P W/ the waits, you can still use them, but as I said in my answer, it gets pretty complicated. If you wish, I could go into detail about how you can accomplish this, but it may be a bit overloading. ;-;
Like the comment above said, you could use math.random(). I'd also like to add that you don't really need all of those sound variable and should just store them in an array/table along with their individual length. It'd look something like: local s = {{id,length},{id,length},{id,length}} To load them you'd just do local ran = math.random(1,#s) and then load the asset by doing s[ran][1] and telling
Updated my comments on my answer. :P