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

How do I make a randomized, shuffled music playlist?

Asked by 6 years ago

There's this script that I want to modify it; when you click the button, it plays music but how can I make it so it plays different songs along with it too like a playlist? Here's the script;

bin = script.Parent
function Clicked()
    bin.Parent.Sound.SoundId = "rbxassetid://142372565"
    bin.Parent.Sound:Play()
    wait(125)
end
bin.MouseButton1Down:connect(Clicked)

Also is it possible that I can remove the

wait(125)

part and make it so that it automatically changes into another song once it ends without having to specifically count 125 seconds?

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

If I am thinking correctly this is what you want.

local bin = script.Parent
--Create a table to store all your songs
local songs = {
    'rbxassetid://142372565',
    'rbxassetid://54654',
    'rbxassetid://233',
    'rbxassetid://123',
    'rbxassetid://asd',
    'rbxassetid://ds',
    'rbxassetid://djdjdj',  
}

-- Clicked Event
bin.MouseButton1Down:connect(function()
    bin.Parent.SoundId = tostring(songs[math.random(1, #songs)]) --Picks a random song from table
    bin.Parent.Sound:Play()
    wait(bin.Parent.Sound.TimeLength)
end)

However, if you want it to play forever then do this

bin.MouseButton1Down:connect(function()
while true do
    wait()
    bin.Parent.SoundId = tostring(songs[math.random(1, #songs)]) --Picks a random song from table
    bin.Parent.Sound:Play()
    wait(bin.Parent.Sound.TimeLength)
    end)
end
0
Didn't work at all! When I click button, nothing happens now! ShadowNinja1080 6 — 6y
0
This script worked perfectly fine for me YouSNICKER 131 — 6y
Ad

Answer this question