How do I randomise these list of ids that are played?

Hi there, I have a music playlist script that plays of on one sound only, and it goes of a list of id’s in a script. However I want it to be randomised instead of randomised.

music = {
	"rbxassetid://3044286747", --here put the ids of the music
	"rbxassetid://1256391355",
	"rbxassetid://5480102561",
	"rbxassetid://5024527209",
	"rbxassetid://4492941290",
	"rbxassetid://870242868",
	"rbxassetid://1112109949",
	"rbxassetid://6303331764",
	"rbxassetid://2206587324",
	"rbxassetid://5604871403",
	"rbxassetid://5987864893",
	"rbxassetid://534429024",
	"rbxassetid://3616424949";

}

while true do 

	for i = 1, #music do

		local currentmusic = music[i]
		local SongID = string.match(currentmusic, "%d+")
		local SongInfo = MPS:GetProductInfo(SongID)

		musicplayer.SoundId = currentmusic 
		musicplayer:Play() 
1 Like

maybe you should do something like
i = math.random(1,array.length)

and do

music[i]:Play()

Im not giving the code to you im giving advice on how you are gonna do that

Have a good day

1 Like

I understand dude, I may of made that topic too spoiled. Also for the line, “music[i]:Play(),” would i have to change the last line and replace it with that? What changes would that serve?

You can use math.random & get the length of the table using the # operator, which in your instance would be a total of 12-14’ish songs

Instead of using a for 1 = 1 loop to go through the table in a chronological order, choose a random song from 1 of the songs inside the table, detect if a sound is valid to play (If it is, then play it) then wait for the song to end to play another random song:

local RandomSong = music[math.random(1, #music)] 
local SongID = string.match(RandomSong, "%d+")
local SongInfo = MPS:GetProductInfo(SongID)

musicplayer.SoundId = RandomSong
musicplayer:Play()

quick question, what does this string mean?

"%d="

A very complicated, yet simple string

%d would be detecting only digits inside the string you’re attempting to search for (1, 50, 49483, etc)

+ would be allowed to detect more than 1 string & would keep going until the string ends

local String = "200"

local Example1 = string.match(String, "%d")
print(Example1) --This would only print the first number inside the string, or "2" as there's no modifier
local String = "200"

local Example2 = string.match(String, "%d+")
print(Example2) --This however would print all the numbers inside the string, or "200"

The + symbol is basically a modifier, as it modifies what you’re attempting to look for

1 Like

i forgot to mention but inside of the whole script, a sound instance is added

As long as you’re able to reference the Sound Instance inside the script, then it should work fine provided the math.random() example I gave

hmm seems like i did something wrong. no errors were shown in output

local musicplayer = Instance.new("Sound",workspace) 

music = {
	"rbxassetid://3044286747", --here put the ids of the music
	"rbxassetid://1256391355",
	"rbxassetid://5480102561",
	"rbxassetid://5024527209",
	"rbxassetid://4492941290",
	"rbxassetid://870242868",
	"rbxassetid://1112109949",
	"rbxassetid://6303331764",
	"rbxassetid://2206587324",
	"rbxassetid://5604871403",
	"rbxassetid://5987864893",
	"rbxassetid://534429024",
	"rbxassetid://3616424949";

}

while true do 

	local RandomSong = musicplayer[math.random(1, #music)] 
	local SongID = string.match(RandomSong, "%d+")
	local SongInfo = MPS:GetProductInfo(SongID)

	musicplayer.SoundId = RandomSong
	musicplayer:Play()

Ah

You should be getting the table inside first, but instead you got the musicplayer which is referencing the Sound you inserted inside the workspace

Try replacing that line with this:

	local RandomSong = music[math.random(1, #music)]

works now thanks!
abcdefghijklmn