Codectionary / Developer documentation / Luau

Instances, properties and methods

Instances form the Roblox object tree. Properties describe an object, methods perform operations, and events report changes. Check the class before using class-specific properties; a child with the right name can still be the wrong kind of object.

Syntax

local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace

Examples

Configure before parenting

Script in ServerScriptService. Parenting last exposes a fully configured block to the scene. Destroy removes it after a short demonstration lifetime.

local part = Instance.new("Part")
part.Name = "TemporaryMarker"
part.Anchored = true
part.Position = Vector3.new(0, 6, 0)
part.Size = Vector3.new(2, 2, 2)
part.Parent = workspace
task.delay(5, function()
    part:Destroy()
end)

Narrow the class before changing a property

Script in ServerScriptService. Create a Folder named LessonParts in Workspace and put several Parts inside it. Only direct BasePart children are changed; nested descendants are intentionally excluded.

local folder = workspace:WaitForChild("LessonParts")
for _, child in folder:GetChildren() do
    if child:IsA("BasePart") then
        child.Color = Color3.fromRGB(70, 140, 220)
    end
end

Best practices

  • Use colon syntax for instance methods such as part:Destroy().
  • A destroyed instance should not remain the owner of later work; cancel or disconnect callbacks that no longer have a purpose.
  • Choose GetChildren or GetDescendants deliberately; a recursive search can touch far more objects than intended.

At a glance

Purpose
Typed scripting and Roblox development
File extension
.luau
Runs in
Luau host; Roblox engine examples require Roblox Studio
Usually used with
Roblox APIs and Studio

Specifications & further reading

Related Luau documentation