Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 4 years ago
Edited 4 years ago

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()
0
This is because the variable RandomMap is returning a number IAmNotTheReal_MePipe 418 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

0
I deleted mine since it was overcomplicated and used up more than 6 more lines than your answer. youtubemasterWOW 2741 — 4y
0
It was good, anyways i appreciate the answer, i always do! :D @YoutubeMasterWOW maxpax2009 340 — 4y
Ad
Log in to vote
-1
Answered by
Nckripted 580 Moderation Voter
4 years ago
local musicOptions = {soundId1,soundId2}

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

Try using sound ids instead.

Answer this question