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

How do I make a script that chooses something randomly out of a set?

Like instead of picking randomly 1 through 5, the set would be (1,4,7,18,224) or something like that and it would pick randomly from that.

3 answers

✓ Accepted answer

To do this you'll have to use the math.random() method and create a table.

local table = {1, 4, 7, 18, 224} -- You can input any numbers or strings that you wish to add.

local RANDOM_NUMBER = table[math.random(#table)] -- Here is the variable getting an arbitrary number from the table above.

print(RANDOM_NUMBER) -- Printing the number that was randomly chosen from the table.

You can learn more about Tables and Mathematical Functions Here:

http://wiki.roblox.com/index.php?title=Table

http://wiki.roblox.com/index.php?title=Random_numbers

http://wiki.roblox.com/index.php?title=Global_namespace/Mathematical_functions

I think you need a table, which works like this:

Table = {"1","2","3"}
Random = Table[math.random(#Table)]

Something along those lines

Table = {1,4,7,18,224}
NumberChosen = Table[math.random(#Table)]
print(NumberChosen)

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