Med Written By ForeverKyIe

Random Tables Created on: 01-01-2019

Learn how to use "random" on a table.

A "table" can be simple expressed as an algebraic table. One side it shows the place of the value / string, and the other size is what it is equalled to.

Here is an example of a table:

local woodenTable = {3,4,2,6}
-- The number "3" is the first digit, the number "4" i the second digit,
-- the number "2" is the third digit, and the number "6" is the fourth.

Here is an example of how you can print the part of the table you want:

print(woodenTable[1])

This will allow me to print the first digit, the "3", into the output.

But, finding a random digit in the table is a little bit harder.

print(woodenTable[math.random(1,#woodenTable)])

Instead of typing a digit into between the square brackets, I instead replaced it with a math.random function. The "1" between the brackets (for the math.random), represents the minimum, or in this case, it just lets me find a random in all of the table.

The "#woodenTable" is the maximum, or in this case, what the script is limited to choosing, which is whatever is in the table. The "#" means "number", and it will change the "woodenTable" variable into the amount of digits within the table. So, with the "#woodenTable", the script is able to only choose digits that are within the table. In my case, I have only 4 digits to choose from: 3,4,2, and 6.

Med Written By ForeverKyIe

See ForeverKyIe's profile on Roblox

Discussion