Roblox objects and events, lesson 21
Properties
Goal: Change how an object looks and behaves from code.
about 5 min3 practice exercises
Instances have properties: named settings you can read and change. You see them in Studio's Properties window, and you set them from code with a dot and =.
local gate = workspace.Gate
gate.Transparency = 0.5 -- 0 is solid, 1 is invisible
gate.CanCollide = false -- players can walk through
gate.Anchored = true -- it will not fall or be pushed
gate.Color = Color3.fromRGB(0, 170, 255)
That is a whole "open the gate" effect: see-through and walk-through.
You can also create instances from code. Set the properties first and the parent last:
local coin = Instance.new("Part")
coin.Name = "Coin"
coin.Size = Vector3.new(2, 2, 2)
coin.Anchored = true
coin.Parent = workspace
An instance with no parent exists but is not in the game. Setting Parent is what makes it appear.
Property names are case sensitive, like everything in Luau. gate.transparency is an error.
Try it in Studio
Optional, and the best way to make it stick.
Select a Part and change Transparency in the Properties window, then make the same change from a Script.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.