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 music play in shuffle?

Hey, I'm trying to make like music player with songs that don't go in order, but instead they are shuffled and don't play in order. Here's script;

while true do
	script.Parent.SoundId= "rbxassetid://142304703" --1 Fortunate Son
	script.Parent:Play()	
	wait(120)
	script.Parent.SoundId= "rbxassetid://142304778" --2 I Can See Clearly Now
	script.Parent:Play()	
	wait(120)
	script.Parent.SoundId= "rbxassetid://142304968" --3 Imagine
	script.Parent:Play()	
	wait(120)
	script.Parent.SoundId= "rbxassetid://142305080" --4 Lets Groove
	script.Parent:Play()	
	wait(120)
	script.Parent.SoundId= "rbxassetid://142305170" --5 Mercy Me
	script.Parent:Play()	
	wait(120)

They play in order, but I want them to play randomly in any order. How do I modify it?

1 answer

Here's how I would do a song shuffle. Random isn't exactly good enough because you can get the same song twice.

We will construct a table of soundids to use, use a separate table to track what songs we still want to play, remove sound ids based on the known size of the table randomly, and loop.

function clonetable(org)
  return {table.unpack(org)}
end

ids = {"rbxassetid://142304703", "rbxassetid://142304778", "rbxassetid://142304968", "rbxassetid://142305080", "rbxassetid://142305170"}

while true do
   idstouse = clonetable(ids)
   for i = 5,1,-1 do
      script.Parent.SoundId = table.remove(math.random(1,i))
      script.Parent:Play()
      wait(120)
   end
end

4 comments

0

About the waiting time, you see the 120 wait time in my original script was intended to be like the length of song until it changes to another. Will this shuffle script affect the songs length? Because I'm planning to add songs that are not the same 120 length.

0

And also your script doesn't work. No songs play.

0

He gave you a method. In no way is he obligated to give you direct code

0

Use Sound:Ended to catch when the song ends http://wiki.roblox.com/index.php?title=API:Class/Sound/Ended

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