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

How to make a random music picker? [SOLVED, thanks to ArtsicleOfficial!]

So to expand, i created a random sound player, but it does not work.

It's not playing the music. I hope there is an easy solution for this...

ERROR: Attempt to index number with "Play"

local Musics = game.Workspace.Music:GetChildren()
			
		local RandomMap = math.random(1, #Musics)
		RandomMap:Play()

1 comment

0

This is because the variable RandomMap is returning a number

2 answers

✓ Accepted answer

Here you go!

local RandomMap = Musics[math.random(1, #Musics)]
RandomMap:Play()

The issue is that you were trying to play a number instead of a music track, so you need to remember to use that number to find a music track. These other answers don't seem to understand that fundamental problem of this question.
Edit: At the time there were multiple answers, someone seems to have deleted theirs.
Edit 2: And now you have multiple answers again.
Edit 3: And now you have only one other answer.

2 comments

0

I deleted mine since it was overcomplicated and used up more than 6 more lines than your answer.

0

It was good, anyways i appreciate the answer, i always do! :D @YoutubeMasterWOW

local musicOptions = {soundId1,soundId2}

local musicPicked = math.random(1,#musicOptions)
--What to do with musicPicked

Try using sound ids instead.

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