BrickColor

< Global namespace | Roblox namespace

BrickColor is a datatype that provides a predefined list of colors. In the past, you could only set the color of a Part to a BrickColor, but this has since been expanded to support Color3. BrickColor now just serves as a handy palette of common Roblox part colors.

Each BrickColor has a numeric id, that represents the color. For example, 1 is white, and 45 is a light blue. There are many different colors available, and you can see the list here.

Quick Reference

Constructors
SyntaxDescription
BrickColor.new(string val)Constructs a BrickColor from it's name.
BrickColor.new(int val)Constructs a BrickColor from it's numerical index.
BrickColor.new(number r, number g, number b)Constructs the closest BrickColor that can be matched to the specified RGB components.
BrickColor.new(Color3 color)Constructs the closest BrickColor that can be matched to the specified Color3.
BrickColor.palette(int paletteValue)Constructs a BrickColor from its palette index.

This must be an integer between 0 and 127.

BrickColor.random()Returns a random BrickColor
BrickColor.White()Returns White (1)
BrickColor.Gray()Returns Medium stone grey (194)
BrickColor.DarkGray()Returns Dark stone grey (199)
BrickColor.Black()Returns Black (26)
BrickColor.Red()Returns Bright red (21)
BrickColor.Yellow()Returns Bright yellow (24)
BrickColor.Green()Returns Dark green (28)
BrickColor.Blue()Returns Bright blue (23)
Properties
SyntaxDescription
int Number The unique number that identifies the BrickColor.
string Name The name associated with the BrickColor.
Color3 Color The Color3 associated with the BrickColor.
number r The red component of the BrickColor's Color3 value (between 0 and 1)
number g The green component of the BrickColor's Color3 value (between 0 and 1)
number b The blue component of the BrickColor's Color3 value (between 0 and 1)

Constructors

BrickColor.new

BrickColor.new(string val)

Description:
Constructs a BrickColor from it's name.

BrickColor.new(int val)

Description:
Constructs a BrickColor from it's numerical index.

BrickColor.new(number r, number g, number b)

Description:
Constructs the closest BrickColor that can be matched to the specified RGB components.

Notes:

  • All of the parameters should be numbers between 0 and 1.

BrickColor.new(Color3 color)

Description:
Constructs the closest BrickColor that can be matched to the specified Color3.

BrickColor.palette

BrickColor.palette(int paletteValue)

Description:
Constructs a BrickColor from its palette index. This must be an integer between 0 and 127.

BrickColor.random

BrickColor.random()

Description:
Returns a random BrickColor

Basic Color Constructors

BrickColor.White()

Description:
Returns White (1)

BrickColor.Gray()

Description:
Returns Medium stone grey (194)

BrickColor.DarkGray()

Description:
Returns Dark stone grey (199)

BrickColor.Black()

Description:
Returns Black (26)

BrickColor.Red()

Description:
Returns Bright red (21)

BrickColor.Yellow()

Description:
Returns Bright yellow (24)

BrickColor.Green()

Description:
Returns Dark green (28)

BrickColor.Blue()

Description:
Returns Bright blue (23)

Properties

All of these properties are read-only. You cannot assign them.

BrickColor.Number

int BrickColor.Number [readonly]

Description:
The unique number that identifies the BrickColor.

BrickColor.Name

string BrickColor.Name [readonly]

Description:
The name associated with the BrickColor.

BrickColor.Color

Color3 BrickColor.Color [readonly]

Description:
The Color3 associated with the BrickColor.

BrickColor.r

number BrickColor.r [readonly]

Description:
The red component of the BrickColor's Color3 value (between 0 and 1)

BrickColor.g

number BrickColor.g [readonly]

Description:
The green component of the BrickColor's Color3 value (between 0 and 1)

BrickColor.b

number BrickColor.b [readonly]

Description:
The blue component of the BrickColor's Color3 value (between 0 and 1)

Using BrickColor codes

There are actually two ways to use BrickColor codes, the number code and the color code.

Each code has an id number associated with it. For example, "White" has an id of 1. You can use either the name of the color, or the id number of the color when using the code.

Using Names

Just like before, open up a new place with a part.

In the Command Line, type in this bit here and hit enter:

game.Workspace.Part.BrickColor = BrickColor.new("White")

Instead of telling Lua that you want the brick to be the value of White, or 1, you tell it specifically that you want the brick to be "White". In this case, you used a String instead of a Number.

For a subset of common colors, an alternate notation can be used:

game.Workspace.Part.BrickColor = BrickColor.White()

Using Color3 Values

Color3s contain 3 numbers, representing the red, green, and blue component of the color.

Just like before, open up a new place with a part.

In the Command Line, type in this bit here and hit enter:

game.Workspace.Part.BrickColor = BrickColor.new(Color3.new(1, 1, 1))

This sets the R, G, and B components of the color to full brightness, creating white. Same thing as the above two examples, just a different way to get there.

Color codes

There are actually a great many color codes, not just the 128 colors available in the Color Picker window. The list is available here.

Comparing BrickColors

When comparing BrickColors to other values, you must take care to make sure that values that you're comparing are of the same type, as comparisons between values of different types in Lua *always* returns false (for details, see the note here). To get around this, the property of the BrickColor that is the same type as the other value can be compared instead. See the table below for examples.

Value Type Example
BrickColor brickColor == redPart.BrickColor
String brickColor.Name == "Really red"
Number brickColor.Number == 1004
Color3 brickColor.Color == Color3.new(1, 0, 0)

See Also

Referenced by