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?
01 | while true do |
02 | script.Parent.SoundId = "rbxassetid://142304703" --1 Fortunate Son |
03 | script.Parent:Play() |
04 | wait( 150 ) |
05 | script.Parent.SoundId = "rbxassetid://142304778" --2 I Can See Clearly Now |
06 | script.Parent:Play() |
07 | wait( 128 ) |
08 | script.Parent.SoundId = "rbxassetid://142304968" --3 Imagine |
09 | script.Parent:Play() |
10 | wait( 395 ) |
11 | script.Parent.SoundId = "rbxassetid://142305080" --4 Lets Groove |
12 | script.Parent:Play() |
13 | wait( 183 ) |
14 | script.Parent.SoundId = "rbxassetid://142386715" --26 Can't Touch This |
15 | script.Parent:Play() |
16 | wait( 167 ) |
17 | 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()
.
01 | musicTable = --Making a table of music / your songs |
02 | { |
03 | "rbxassetid://142304703" , -- 1 - Fortunate Son |
04 |
05 | "rbxassetid://142304778" , -- 2 - I Can See Clearly Now |
06 |
07 | "rbxassetid://142304968" , -- 3 - Imagine |
08 |
09 | "rbxassetid://142305080" , -- 4 - Let's Groove |
10 |
11 | "rbxassetid://142386715" -- 5 - Can't Touch This |
12 |
13 | } |
14 |
15 | --Instead of you doing wait(), we can use the event "Ended" |