Hey, I'm trying to make like music player with songs that don't go in order, but instead they are shuffled and don't play in order. Here's script;
while true do script.Parent.SoundId= "rbxassetid://142304703" --1 Fortunate Son script.Parent:Play() wait(120) script.Parent.SoundId= "rbxassetid://142304778" --2 I Can See Clearly Now script.Parent:Play() wait(120) script.Parent.SoundId= "rbxassetid://142304968" --3 Imagine script.Parent:Play() wait(120) script.Parent.SoundId= "rbxassetid://142305080" --4 Lets Groove script.Parent:Play() wait(120) script.Parent.SoundId= "rbxassetid://142305170" --5 Mercy Me script.Parent:Play() wait(120)
They play in order, but I want them to play randomly in any order. How do I modify it?
Here's how I would do a song shuffle. Random isn't exactly good enough because you can get the same song twice.
We will construct a table of soundids to use, use a separate table to track what songs we still want to play, remove sound ids based on the known size of the table randomly, and loop.
function clonetable(org) return {table.unpack(org)} end ids = {"rbxassetid://142304703", "rbxassetid://142304778", "rbxassetid://142304968", "rbxassetid://142305080", "rbxassetid://142305170"} while true do idstouse = clonetable(ids) for i = 5,1,-1 do script.Parent.SoundId = table.remove(math.random(1,i)) script.Parent:Play() wait(120) end end