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 = workspaceCheck 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
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.Client/server boundaries and project structure
A server owns shared game decisions while each client handles its own input, camera and presentation. Treat client messages as requests. Put private rules in server containers and expose only the data and operations the client actually needs.ModuleScripts and exported types
A ModuleScript returns a value for require to use. Keep reusable calculations in modules and choose storage based on who may require them. Requiring the same module on the client and server does not create shared memory between those environments.Script, LocalScript and ModuleScript placement
The same code can behave differently depending on where it runs. These lessons use server Scripts in ServerScriptService and LocalScripts in StarterPlayerScripts or StarterGui. A ModuleScript runs when required. Script RunContext also affects execution, so inspect it when a script appears silent.
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.Client/server boundaries and project structure
A server owns shared game decisions while each client handles its own input, camera and presentation. Treat client messages as requests. Put private rules in server containers and expose only the data and operations the client actually needs.ModuleScripts and exported types
A ModuleScript returns a value for require to use. Keep reusable calculations in modules and choose storage based on who may require them. Requiring the same module on the client and server does not create shared memory between those environments.Script, LocalScript and ModuleScript placement
The same code can behave differently depending on where it runs. These lessons use server Scripts in ServerScriptService and LocalScripts in StarterPlayerScripts or StarterGui. A ModuleScript runs when required. Script RunContext also affects execution, so inspect it when a script appears silent.