Is this script correct?

Hi, so I’ve been trying to teach my self lately with math.Random and tables. I just want feedback for this simple script I made, or any other way to make it better

The Script:

local Colors = {"Really Red", "Really Blue", "New Yeller"}

print(math.Random[Colors])

1 Like

Colors(math.random[#Colors])

1 Like

It should be

printColors(math.random[#Colors])

?

1 Like

The function math.function() only takes numerical parameters. When you called it here …

You passed in colors into the parameter, which is a table. You cannot pass tables into this function. I presume you wanted to print a random color, in which case you need to use the # operator which will return the length of a table. Like this …

print(Colors[math.random[#Colors]])

Here your taking a random number from 1 to the last index of the table so it will return a random index in the table, and using the [] operator you access the value at that index and print it.

3 Likes

Right, It makes sense now! Thanks, Have a good day/night

2 Likes