Hello, I made GUI of where you click button and it plays songs. What I did was made a button GUI and added an empty Audio inside of it. Then inside the empty Audio, I added a script which is below. It works well but the only problem, I want to make it when you click, the list of songs in script don't go in order, they are shuffled. How do I do that?
while true do script.Parent.SoundId= "rbxassetid://142304703" --1 Fortunate Son script.Parent:Play() wait(150) script.Parent.SoundId= "rbxassetid://142304778" --2 I Can See Clearly Now script.Parent:Play() wait(128) script.Parent.SoundId= "rbxassetid://142304968" --3 Imagine script.Parent:Play() wait(395) script.Parent.SoundId= "rbxassetid://142305080" --4 Lets Groove script.Parent:Play() wait(183) script.Parent.SoundId= "rbxassetid://142386715" --26 Can't Touch This script.Parent:Play() wait(167) end
Also, the "wait()" is the amount of time that song plays. For example a song that is "wait(128) is 1:28 seconds long. Just so you know. But anyways how can I make them play in a shuffled order?
None of those waits are correct. wait(128)
is NOT 1:28 / one minute and 28 seconds. One minute is 60 seconds. We can make the script choose something randomly by using math.randomseed(tick())
and math.random()
.
musicTable = --Making a table of music / your songs { "rbxassetid://142304703", -- 1 - Fortunate Son "rbxassetid://142304778", -- 2 - I Can See Clearly Now "rbxassetid://142304968", -- 3 - Imagine "rbxassetid://142305080", -- 4 - Let's Groove "rbxassetid://142386715" -- 5 - Can't Touch This } --Instead of you doing wait(), we can use the event "Ended" math.randomseed(tick()) --Creates a new seed every time(basically makes more random) while true do local randomSong = musicTable[math.random(1, #musicTable)] wait(5) -- Just creating a small pause before a random song plays script.Parent.SoundId = randomSong --Choose song script.Parent:Play() --Play song script.Parent.Ended:wait() -- Waiting until the song has finished end