beginner
30 min

Introduction to Roblox API

Get started with Roblox-specific functions and the game hierarchy.

WorkspacePlayersServicesInstance Properties

1
The Roblox Hierarchy

Roblox games are organized in a tree structure with game as the root.

Accessing Services

-- Get important services
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Shorter way for Workspace
local workspace = game.Workspace  -- or just 'workspace'

Services are the top-level containers in Roblox. Use GetService() for best practice.

2
Working with Parts

Parts are the basic building blocks in Roblox.

Creating and Modifying Parts

-- Create a new part
local part = Instance.new("Part")
part.Size = Vector3.new(10, 5, 10)
part.Position = Vector3.new(0, 10, 0)
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.Neon
part.Parent = workspace

-- Make it anchored (won't fall)
part.Anchored = true

Always set Parent last to avoid performance issues!

Finding Parts

-- Find by name
local myPart = workspace:FindFirstChild("PartName")

if myPart then
  print("Found the part!")
  myPart.Transparency = 0.5
end

-- Get all children
for _, child in ipairs(workspace:GetChildren()) do
  print(child.Name)
end

Always check if FindFirstChild() returns nil before using it!

3
Working with Players

Access and manipulate player data.

Player Events

local Players = game:GetService("Players")

-- When a player joins
Players.PlayerAdded:Connect(function(player)
  print(player.Name .. " joined the game!")
end)

-- When a player leaves
Players.PlayerRemoving:Connect(function(player)
  print(player.Name .. " left the game!")
end)

Events use :Connect() to run functions when something happens.

Accessing Player Character

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
  -- Wait for character to load
  player.CharacterAdded:Connect(function(character)
    local humanoid = character:WaitForChild("Humanoid")
    print(player.Name .. "'s health: " .. humanoid.Health)
  end)
end)

Use WaitForChild() to ensure parts exist before accessing them.

💡 Tips:

  • • Always use game:GetService() instead of game.ServiceName
  • • Check if objects exist before using them (nil checks)
  • • Use WaitForChild() when you need to wait for an object to exist

Practice Exercises

Exercise 1: Create a Part

Create a blue neon part in the workspace.

Starter Code:

-- Create your part here
Show Solution
local part = Instance.new("Part")
part.Size = Vector3.new(5, 1, 5)
part.Position = Vector3.new(0, 5, 0)
part.BrickColor = BrickColor.new("Really blue")
part.Material = Enum.Material.Neon
part.Anchored = true
part.Parent = workspace

Exercise 2: Welcome Players

Print a welcome message when players join.

Starter Code:

local Players = game:GetService("Players")

-- Write your PlayerAdded event here
Show Solution
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
  print("Welcome to the game, " .. player.Name .. "!")
end)

Ready for more?

Continue your learning journey

Executors.Online - Your Roblox Developer Hub