local codes = {2, 3}
local Code = tostring(codes[math.random(1, #codes)])
im kind of a noob at scripting but there is this table that chooses one of the codes randomly and how do i detect which number is chosen because I want to make it so that if it chooses “1” then a part will be red, if it chooses “2” then a part will be green and “3” will be blue.
Well firstly, you should note that tables aren’t limited to numbers only. Anything can be placed in a table. Even another table!
knowing this you can do:
local colors = {
BrickColor.new('Really red'),
BrickColor.new('Really blue')
}
local color = colours[math.random[1,#colors]]
workspace.Part.BrickColor = color
Using math.random converts all the options into a numerical order. In fact all tables can be used in numerical order. If you say colors[1], that would return the first value in that table, same as with colors[2], will return the second value in the table.