I have this script that I made. and it doesnt work... Sorry I'm still getting the hang of it..
local Colors = { BrickColor.new("Lime green"), BrickColor.new("Hot pink"), } script.Parent.BrickColor = [1#math.random()Colors]
What are tables?
Tables
are basically dictionaries for Lua
. Tables can be called either like:
local exampletable = {"I think I'm pretty", "I think I'm codey", "I think I'm helpy"}
Or like:
local exampletable = { "I think tables are cool", "I think tables are useful", "I think tables are helpy"}
For your case, you will just want to put the BrickColor
names as strings. Here, I'll fix your table code:
local Colors = { "Lime green", "Hot pink"}
What is BrickColor?
BrickColor is a constructor used in changing colors of Parts. To change it, you must do it as such:
script.Parent.BrickColor = BrickColor.new("Lime green")
But you want to implement a random color. So you would use math.random()
to pick a random color out of your table. But how do we access contents of a table? Using the # operator. Yes, we are going to start a fanbase of #Colors. To implement this random color picker, just do this:
script.Parent.BrickColor = BrickColor.new(math.random(1, #Colors))
This is just a simple way of picking colors out from a table. If you want full randomness, you can use Color3
.
script.Parent.BrickColor = Color3.new(math.random(1, 255) / 255, math.random(1, 255) / 255, math.random(1, 255) / 255)
This code will give you a completely random color.
local Colors = { BrickColor.new("Lime green"), BrickColor.new("Hot pink"), } script.Parent.BrickColor = Colors[math.random(#Colors)]