Object Properties

Properties control how objects look and function. Each object in Roblox Studio has it's own set of properties. For example, a part object has properties for color, size, and shape. Properties can be changed using the Roblox Studio interface, or through scripts.

To learn about properties, you'll explore common properties found in parts and then write a script to change part colors.

The Properties Window

Many of an object's properties are shown in the Properties Window.

  1. Select a part.

  2. Scroll through the Properties Window on the bottom right. If you don't see the window, go to the View tab and click the Properties button.

Changing Properties

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

Setting up the Part and Script

Since this is a practice script, it can be used in any simple template, such as the Baseplate or Flat Terrain.

  1. In a new project, select an existing part or create a new one. Rename the part PracticePart.

  2. In ServerScriptService, create a new script named ChangeColor.

  3. In the script, delete the "Hello World" line. Then, write a comment by typing -- and then including a brief description of what the script will do.


    -- Changes the color of a part

Locating 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.

The specific path to find this part, such as Workspace to Practice part, needs to be translated into something a script can understand.

  1. Under the comment, type game. This gives you access to the Workspace.


    -- Changes the color of a part
    game.
  2. Use dots to separate words. On the same line, type . followed by Workspace, the location of the part. Finish it by typing another dot and the name of your part.


    -- Changes the color of a part
    game.Workspace.PracticePart

Changing a Property with Code

To change the color of the part, you'll use an RGB value. Computers use RGB values, the combination of red, green, and blue to create all the colors on your screen.

RGB values use three numbers from 0 to 255, separated by commas. For example, black is (0, 0, 0) while white is (255, 255, 255).

For the part, the script will change it's Color property to a new Color3, a data type that stores colors.

  1. After PracticePart, type .Color to access the color property.


    -- Changes the color of a part
    game.Workspace.PracticePart.Color
  2. Continue by typing ==, allowing you to set that color to something new. Then, set it to Color3.fromRGB(). The will allow you to create a new color.


    -- Changes the color of a part
    game.Workspace.PracticePart.Color == Color3.fromRGB()
  3. While colors can be manually typed inside the parentheses, it's easier to use a color picker. Click inside the parentheses, and then click the color wheel. Follow the popup to create a color.

    Your code should look like below, but may have a different RGB value.


    -- Changes the color of a part
    game.Workspace.PracticePart.Color == Color3.fromRGB(255, 230, 50)
  4. Press Play to test that your part changes color.

Troubleshooting Tips

If the part doesn't change color, try one of the tips below.

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.
  • Double check that the capitalization and spelling is the same as the code example. color3 will not work, while Color3 will work. Subtle differences can cause errors.