Menu
CoddyTech

Paint a Part

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 2 of 25.

A part has properties: its color, what it is made of, how see-through it is, its size and where it is. Changing a property changes the part in the game at once.

A script that sits inside a part reaches that part through script.Parent. Store it in a variable so you can use it on every line:

local block = script.Parent
block.Color = Color3.fromRGB(0, 120, 255)

local block creates a variable named block, and = puts a value in it. Color3.fromRGB mixes a color from red, green and blue, each from 0 to 255, so 0, 120, 255 is a bright blue.

Some properties take a value from a list Roblox gives you, called an Enum. The material is one of them:

block.Material = Enum.Material.Wood

Transparency is a number: 0 is solid, 1 is invisible, and anything in between is see-through.

challenge icon

Challenge

Easy

Paint the gray block by changing the values in its three lines.

  1. In the block.Color line, change the numbers to 255, 0, 0.
  2. In the block.Material line, change Plastic to Neon.
  3. In the block.Transparency line, change 0 to 0.5.

Press Play: the block glows red and you can see through it. Then Check.

Try it yourself

local block = script.Parent

-- 1. Make the block red: change the three numbers to 255, 0, 0
block.Color = Color3.fromRGB(163, 162, 165)

-- 2. Make it glow: change Plastic to Neon
block.Material = Enum.Material.Plastic

-- 3. Make it half see-through: change 0 to 0.5
block.Transparency = 0

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler