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.WoodTransparency is a number: 0 is solid, 1 is invisible, and anything in between is see-through.
Challenge
EasyPaint the gray block from its script by changing the three values.
- Make it red:
Color3.fromRGB(255, 0, 0). - Make it glow:
Enum.Material.Neon. - Make it half see-through:
Transparency0.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
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler