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

How to select a(n) item from a table by math.Random or something else ?

So i have a table containing musicid:

local table = {"26616646","516165131","151656548"} -- they are not real (if they are real...idk)
local Random = math.Random(1,#table)
print(Random)

at first I thought that it will print the music id but it is printing 1, 2,3.... So how do i get the music id to be print out randomly ? Please help me as i am a very bad scripter... Thanks for reading :D

1 answer

✓ Accepted answer

Change it to this:

local table = {"26616646","516165131","151656548"}

local Random = math.Random(1,#table)

local ChosenSong = table[Random]

print(Random)

#table gives the number of objects in the table, in your case, 3. Math.random returns a number and not an object or a word.

5 comments

0

Oops sorry change the "Random" at line 7 to "Chosen song

0

The reason it was printing 1, 2, 3 was because the hashtag mean't numbers of items in your table.

0

oh ok i will test it..thx

0

@JesseSong ...As i said.. i am very bad at scripting :)

0

@JesseSong are you rewriting my answer? Cuz we don't copyright here

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