So i tried to make simple randomizer that changes part color randomly from pre-defined set of colors
After some trial & error, i almost pulled it off, but then i encountered major roadblock that i can’t resolve:
local randomnumber = math.random(1, 3)
local brick = script.Parent
a = 'One'
b = 'Two'
c = 'Three'
if randomnumber == 1 then
print (a)
brick BrickColor.new ("Really red")
end
if randomnumber == 2 then
print (b)
brick BrickColor.new ("Really blue")
end
if randomnumber == 3 then
print (c)
brick BrickColor.new ("Dark green")
end
This line is claiming variable “brick” is incorrect by outputting: Incomplete statement: expected assignment or a function call brick BrickColor.new ("Really red")
local randomnumber = math.random(1,3);
local colors = {
"Really red";
"Really blue";
"Dark green";
};
print(randomnumber);
brick.BrickColor = BrickColor.new(colors[randomnumber]);
Basically, how does colors[randomnumber] works is it will get the index from the colors table, and return the matching string.
Let’s say that randomnumber is 2, colors[2] will be "Really blue" (cause “Really blue” is second in the list)
If you don’t understand tables or indexes, you can read more about them here.