I am trying to make a random color script, but only with a few select colors, am I doing this right?
RandomNumber = math.random(1,10) 1 = 38 2 = 303 3 = 106 4 = 105 5 = 192 6 = 365 7 = 333 8 = 217 9 = 1017 10 = 18 script.Parent.BrickColor = RandomNumber
No, you did not make the script right.
You have several issues with your script.
BrickColor.new()
.{ index=1&value=38, index=2&value=303 }
just try to imagine the table like that. You're not necessarily setting numbers to numbers in this table.I wouldn't necessarily use numbers as they would become difficult to translate to BrickColors. If you do use numbers, just leave a comment for yourself to find out which color is which. That way if you want to add or remove a color, they'd be easy to find. Alternatively, you can use the color names in string form in the table.
So, on line 1 we're defining the table and taking all the BrickColor values you wanted into it. On line 13, we're setting the script's parent line color to a new BrickColor value.
Line 13 may seem confusing. We're setting the BrickColor property to a BrickColor value with BrickColor.new()
. Within BrickColor.new()
we are using the variable for the table which is BrickColors. With the BrickColors table, we're using the brackets as a form of indexing the table. Since the table is in order in terms of indexing, we can use math.random() to get us a random number between 1 and however many entries are in the table. The only necessary argument is how many entries are in the table. We can easily indicate how many entries are in a table by just using the #
operator.
BrickColors = { 38, --Dark orange 303, --Dark blue 106, --Bright orange 105, --Br. yellowish orange 192, --Reddish brown 365, --Burnt Sienna 333, --Gold 217, --Brown 1017, --Deep orange 18, --Nougat } script.Parent.BrickColor = BrickColor.new(BrickColors[math.random(#BrickColors)])