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 7 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;

1bin = script.Parent
2function Clicked()
3    bin.Parent.Sound.SoundId = "rbxassetid://142372565"
4    bin.Parent.Sound:Play()
5    wait(125)
6end
7bin.MouseButton1Down:connect(Clicked)

Also is it possible that I can remove the

1wait(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 7 years ago
Edited 7 years ago

If I am thinking correctly this is what you want.

01local bin = script.Parent
02--Create a table to store all your songs
03local songs = {
05    'rbxassetid://54654',
06    'rbxassetid://233',
07    'rbxassetid://123',
08    'rbxassetid://asd',
09    'rbxassetid://ds',
10    'rbxassetid://djdjdj'
11}
12 
13-- Clicked Event
14bin.MouseButton1Down:connect(function()
15    bin.Parent.SoundId = tostring(songs[math.random(1, #songs)]) --Picks a random song from table
16    bin.Parent.Sound:Play()
17    wait(bin.Parent.Sound.TimeLength)
18end)

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

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

Answer this question