Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a randomized, shuffled music playlist?

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

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

2 comments

0

Didn't work at all! When I click button, nothing happens now!

0

This script worked perfectly fine for me

This discussion is preserved as it was. New answers, comments, and votes are closed.