Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make music playlist shuffle?

Asked by 7 years ago

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?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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
0
It works but the only problem is when I enter a game, it starts playing the music even though I never clicked the GUI! I want to make it so you click the GUI, it starts playing. Not when you immediately enter a server. ShadowNinja1080 6 — 7y
0
Ok, I see. Just modify the script to how you want it Subaqueously 11 — 7y
0
Actually, invite me to the team create so that I can help Subaqueously 11 — 7y
0
btw, that's not a problem. you just need to have a function in the script for example, gui.TextButton.MouseButton1Click:Connect(function() --code here end) Subaqueously 11 — 7y
View all comments (10 more)
0
What part of the script I can put this function? ShadowNinja1080 6 — 7y
0
well, i don't know where everything in your game is so i can't help you unless i'm in Team create Subaqueously 11 — 7y
0
I don't know, I did put your name for invitation for team create but nothing happened. ShadowNinja1080 6 — 7y
0
you have to tell me what game it is and give me the link ,-, Subaqueously 11 — 7y
0
I'm sorry for making things complicated for you. I was inactive from ROBLOX recently and haven't used studio in more than a year so that's why I have lack of knowledge of Team Create and etc. But for some reason now it doesn't play music while I join game. Hold on yet, I'll send you link when I need your help. ShadowNinja1080 6 — 7y
0
Your song script does make music but the only problem it just repeats one music, that's it. The music just goes looped without changing it to a different song. By the way, this is where I'm testing; https://www.roblox.com/games/175535220/School-setttt ShadowNinja1080 6 — 7y
0
By the way, there seems to be wrong with "local randomSong = musicTable[math.random(1, #musicTable)]" because it doesn't play random songs at all. It just keeps looping the first song that comes on. ShadowNinja1080 6 — 7y
0
Ok, so I got it to not looped because I changed from "[math.random(1, #musicTable)]" to "[math.random(0, #musicTable)]". I don't know about that, but now it doesn't replay one song for me. ShadowNinja1080 6 — 7y
0
Sometimes it still loops and remains in one song but other times I saw it switch to another song. Wierd. Must be ROBLOX glitch. ShadowNinja1080 6 — 7y
0
You are only supposed to call math.randomseed once on the server/client, not repeatedly. Due to a quirk in how its implemented, similar values will produce almost identical first random numbers (which is exactly what ShadowNinja is running into). chess123mate 5873 — 7y
Ad

Answer this question