Codectionary / Developer documentation / Luau

game, workspace and storage services

game is the root DataModel and workspace holds the active 3D world. GetService obtains engine services by class name. ReplicatedStorage is visible to both sides; ServerStorage holds objects clients should not receive until the server places them into a replicated location.

Syntax

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

Examples

Create a server-only template

Script in ServerScriptService. The unparented part is configured, then stored outside the visible world. It does not appear in the scene until cloned into Workspace.

local ServerStorage = game:GetService("ServerStorage")
local template = Instance.new("Part")
template.Name = "LessonPlatform"
template.Anchored = true
template.Size = Vector3.new(8, 1, 8)
template.Parent = ServerStorage
local platform = template:Clone()
platform.Position = Vector3.new(0, 4, 0)
platform.Parent = workspace

Check a required object without waiting forever

A separate Script in ServerScriptService. Create an anchored Part named SpawnMarker in Workspace first. FindFirstChild returns immediately; a failed lookup can produce a useful setup message.

local marker = workspace:FindFirstChild("SpawnMarker")
if not marker or not marker:IsA("BasePart") then
    warn("Create a BasePart named SpawnMarker in Workspace")
    return
end
print(marker.Position)

Best practices

  • Use GetService for services rather than relying on an Explorer display name.
  • Use WaitForChild when an object is expected to arrive later, and handle timeouts when its presence is uncertain.
  • Do not poll the whole Workspace each frame to locate an object you can retain or track with events.

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