Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Parts, Physics and Building

Creating and Configuring Parts in Code

Build parts with Instance.new, set Size, Position, Color, Material, Shape and Transparency, set Parent last, build with loops, and tidy parts into models and folders.

Parts are the bricks of Roblox: floors, walls, platforms, coins, hazards. You have placed them by hand; now you will create them from code. Making parts with a script lets you build a staircase in four lines, spawn a coin every second, or generate a whole obstacle course.

The Part class

A Part is a single 3D block. Its Shape can be Block (default), Ball, Cylinder, Wedge or CornerWedge. Other solid classes, such as MeshPart (a custom 3D mesh), share the base class BasePart and its properties.

Key properties of every part:

Property Type Meaning
Size Vector3 Width, height, depth in studs (default 4, 1, 2)
Position Vector3 Centre of the part in the world
Orientation Vector3 Rotation in degrees (X, Y, Z)
Color Color3 Exact colour
BrickColor BrickColor Older named-colour system
Material Enum.Material Plastic, Wood, Neon, Glass, Metal, Grass...
Transparency number 0 solid, 1 invisible
Reflectance number 0 matte to 1 mirror
Anchored boolean Fixed in place if true
CanCollide boolean Solid to other parts if true

Making a part

Create a part with Instance.new, configure it, and set Parent last:

LUA
local platform = Instance.new("Part")
platform.Name = "Platform"
platform.Size = Vector3.new(12, 1, 12)
platform.Position = Vector3.new(0, 10, 0)
platform.Color = Color3.fromRGB(80, 200, 120)
platform.Material = Enum.Material.Grass
platform.Anchored = true
platform.Parent = workspace

A part without a parent does not exist in the world. Parenting last is faster, because the engine does not simulate and replicate every property change one at a time, and it prevents flashes of a default grey block.

Instance.new("Part", workspace) still works, but passing the parent as the second argument sets it first, before the other properties. Prefer assigning Parent as the final line.

Colours

Color3.fromRGB(r, g, b) takes 0 to 255 per channel. Color3.new(r, g, b) takes 0 to 1. Color3.fromHSV(h, s, v) takes 0 to 1 and is great for rainbows. The older BrickColor has named colours:

LUA
part.BrickColor = BrickColor.new("Bright red")
part.Color = Color3.fromHSV(0.6, 0.8, 1)       -- a sky blue

Materials and look

LUA
part.Material = Enum.Material.Neon      -- glows
part.Transparency = 0.5                 -- see-through
part.Reflectance = 0.2                  -- a little shiny
part.Shape = Enum.PartType.Ball         -- a sphere

Neon parts glow brightly, especially in dark lighting. Glass is transparent and reflective. Keep Transparency at 0 unless you need otherwise; transparent parts cost more to render.

Building with loops

Loops make structures cheap. This builds a staircase of ten steps:

LUA
local steps = Instance.new("Folder")
steps.Name = "Staircase"

for i = 1, 10 do
	local step = Instance.new("Part")
	step.Name = "Step" .. i
	step.Size = Vector3.new(8, 1, 4)
	step.Position = Vector3.new(0, i * 1, i * 4)
	step.Anchored = true
	step.Color = Color3.fromHSV(i / 10, 0.7, 1)
	step.Parent = steps
end

steps.Parent = workspace

Parenting each step to a Folder first, then parenting the folder to Workspace last, keeps the Explorer tidy and the build fast. Stairs in Roblox should rise no more than about one stud per stair so the default character can climb them.

Grouping with a Model

A Model groups parts so they move together:

LUA
local house = Instance.new("Model")
house.Name = "House"

local floor = Instance.new("Part")
floor.Size = Vector3.new(16, 1, 16)
floor.Anchored = true
floor.Parent = house

local wall = Instance.new("Part")
wall.Size = Vector3.new(16, 8, 1)
wall.Position = Vector3.new(0, 4.5, -8)
wall.Anchored = true
wall.Parent = house

house.PrimaryPart = floor
house.Parent = workspace
house:PivotTo(CFrame.new(40, 0.5, 0))    -- move the whole house

PivotTo moves the entire model by its pivot. The CFrame lesson explains it.

Cloning templates

If you need many copies of one object, build it once, keep it in ServerStorage, and clone it.

LUA
local ServerStorage = game:GetService("ServerStorage")
local template = ServerStorage:WaitForChild("Coin")

for i = 1, 5 do
	local coin = template:Clone()
	coin.Position = Vector3.new(i * 6, 3, 0)
	coin.Parent = workspace
end

This is how enemies, pickups and bullets are spawned. Remember that Clone returns an instance with no parent.

Cleaning up

part:Destroy() removes a part and its children for good. Parts that fall out of the world are removed automatically at workspace.FallenPartsDestroyHeight (default -500). For temporary effects use game:GetService("Debris"):AddItem(part, 5) to destroy a part after 5 seconds, even if the script that made it ends.

Stand-in: a part factory

Roblox creates parts in the engine. This JavaScript stand-in models the factory pattern: a function builds a part with defaults, applies your settings, and parents it last, then prints the result. It also builds the staircase.

JS Stand-in: Instance.new('Part') and a staircase (JavaScript)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Stand-in: HSV rainbow colours

Color3.fromHSV is the easy way to get evenly spaced colours. This stand-in converts HSV to RGB the way Roblox does, so you can see the rainbow numbers.

JS Stand-in: Color3.fromHSV rainbow (JavaScript)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Performance tips

  • Prefer fewer, larger parts: a wall as one part, not 100 bricks.
  • Anchor everything that should not move; physics is the biggest cost.
  • Set CanCollide = false, CanTouch = false and CanQuery = false on decorative parts.
  • Parent a finished model once, not part by part.
  • Use Debris or Destroy for temporary parts so they do not pile up.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why set Parent as the last line when creating a part?

    Changing properties on a part already in the world costs simulation and network updates, so parent last.
  2. 2. What is Color3.fromRGB(0, 255, 0)?

    The three numbers are red, green, blue from 0 to 255, so this is pure green.
  3. 3. What does Clone return?

    You must set the parent of a clone yourself.
  4. 4. Which Material makes a part glow?

    Neon parts are emissive and glow brightly.

Summary

  • Instance.new("Part"), set properties (Size, Position, Color, Material, Anchored), then set Parent last.
  • Build repeated structures with loops and group them in Folder or Model instances.
  • Clone templates from ServerStorage to spawn many objects; use Destroy or Debris to clean up.
  • Fewer anchored parts and fewer collisions keep the game fast.

Next: Vectors and CFrames