Syntax
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspaceExamples
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
endBest 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.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation