Properties and BrickColor


Properties and BrickColor

Properties control how objects look and function. Some properties an object might have are material, color, or shape. Scripts can change a part’s properties, like making a part change color.

The Properties Window

Many of an object’s properties are shown in the Properties window. To see some properties already being used by objects in your game:

  1. Select a part.
  2. Scroll through the Properties Window on the bottom right.
Can't see the Properties Window?

If you don’t see the Properties window, click the View tab and then click the Properties button.

Changing Properties

The script will use code to change the color of a part at the start of the game.

Set up the Part and Script

  1. Select an existing part or create a new one.
  2. Rename the part. This example uses PracticePart.
  3. Rename the script ChangeBrickColor.
  4. Delete Hello World.

Create a Comment

You should always start new scripts off with a comment about what the script does. Comments are special lines that help coders remember what scripts are for but doesn’t actually run.

  1. Type -- and a note about what this script does. The text should turn green to let you know it’s a comment.

Locate the Part

To make changes to any part using code, the script first needs to know which part to work with. Use the Explorer to find the part’s location. In this case, PracticePart is under Workspace.

Now that you know PracticePart is under Workspace, turn this information into code that the program can understand.

  1. Type game below your comment.
  1. Use dots to separate words. On the same line, type . followed by Workspace, the location of the part.
Using Autocomplete

Roblox will autocomplete words as you type to help speed up the coding process. When the words appear, you can use the arrow keys to move down the list. Pick an option by pressing Enter.

  1. Complete the line with the name of the part like in the example below.
Check Your Code Before Moving On

Make sure your code looks exactly like the code above, and that PracticePart is spelled and capitalized exactly like in the Explorer.

Changing a Property with Code

Almost there! Now, you’ll change the part’s color with the BrickColor property.

  1. Type .BrickColor after the name of your part.

Using RGB Values

To change the BrickColor property, create a new BrickColor to replace the current one. It’s not like mixing paints though, programs use RGB values, the combination of red, green, and blue to create all the colors on your screen.

There are some rules for using RGB values:

  • Use 3 decimal numbers; one for each color.
  • Separate each number with a comma.
  • Use numbers between 0 and 1. 0 means a color is all the way off. 1 means the color is all the way on.

Below are some examples of RGB values:

Color Code

Create a new RGB Color

You’ll now use the = sign to set a new color to replace the original part color. You can use the decimal numbers for the colors in the table above, or come up with your own.

  1. After game.Workspace.PracticePart.BrickColor: type = BrickColor.new()
  1. Inside the parenthesis, add 3 decimal numbers (between 0 and 1), separated by commas. Remember, this is the RGB color value of your part.
  1. Press Play to test that your part changes color.

Issue: Part is still gray or doesn’t change color as intended

  • Make sure you followed all three rules for RGB values (number is 0-1, is a decimal, all numbers separated by commas).
  • If you are doing random numbers, you may get a surprise color.

General Tips

  • Double check that the capitalization and spelling is the same as the code example. Brickcolor will not work, while BrickColor will work.

Previous String Variables Next Loops and BrickColor