colors = {"Really red", "Cyan", "Lime green"} for i = 1,10 do colors[#colors + 1] = BrickColor.Random() wait() end print(table[10]) for i,v in pairs(colors) do print(v) game.Workspace.Baseplate.BrickColor = BrickColor.new(v) wait(2) end
I'm learning how to use tables and I don't understand why I need to use Color3.new(). Even when I use Color3.new(), the script expects BrickColor.new().
When you store the 10 random BrickColors in your colors
table, they are already BrickColor datatypes. So this means that line 11 is like saying BrickColor.new( [BrickColor] )
which doesn't work.
There is a constructor that allows you to input Color3 datatypes as arguments for the BrickColor.new function, which is why you recieved the error :)
If you apply some logical operators, as well as the type
function you can easily get passed this.
The type function returns the datatype of the given value. You can check if the current iteration is either one of your manually inputted strings or a randomly added value, and go about setting the BrickColor property accordingly.
workspace.Baseplate.BrickColor = (type(v) == "string" and BrickColor.new(v)) or v