Roblox Luau Scripting Tutorial for Beginners
Every Roblox game runs on Luau. Even if you use AI to generate your scripts, understanding the language makes you dangerous. You'll read code faster, debug smarter, and prompt better.
Here's what matters.
Scripts in Roblox
Three types:
- Script — runs on the server. Game logic, data saving, security.
- LocalScript — runs on the player's device. UI, camera, input.
- ModuleScript — shared code other scripts can import.
Server scripts control truth. Local scripts control experience. Module scripts prevent repetition.
Variables
local playerName = "Alex" -- string
local health = 100 -- number
local isAlive = true -- boolean
local inventory = {} -- table
local means the variable stays in scope. Always use it. Global variables are bugs waiting to happen.
Functions
local function damage(humanoid: Humanoid, amount: number)
humanoid.Health -= amount
end
Small, named functions. Each one does one thing. This is how you keep scripts readable at scale.
Events
Events are Roblox's nervous system. Something happens, your code responds.
local part = workspace.KillBrick
part.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
:Connect() wires a function to an event. Player touches a part, character dies, button clicked — all events.
Services
Roblox organizes its API into services. The ones you'll use daily:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
Learn these three and you can build most games.
Patterns that matter
Player joins
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
-- handle death
end)
end)
end)
Create a part from code
local part = Instance.new("Part")
part.Size = Vector3.new(10, 1, 10)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Parent = workspace
Client-server communication
Server:
local event = Instance.new("RemoteEvent")
event.Name = "DamageEvent"
event.Parent = game.ReplicatedStorage
event.OnServerEvent:Connect(function(player, targetName)
-- validate and apply damage
end)
Client:
local event = game.ReplicatedStorage:WaitForChild("DamageEvent")
event:FireServer("Zombie1")
Never trust the client. Always validate on the server.
Debugging
print()sends text to the Output window- Red errors crash the script. Fix them first.
- Yellow warnings are informational. Address them second.
- Breakpoints (click the line number margin) let you pause execution and inspect variables
The shortcut
Understanding Luau makes you a better developer. But you don't have to write every line by hand.
Rebirth generates production-quality Luau scripts from English descriptions and executes them directly in your Studio. When you understand the fundamentals from this tutorial, you can read what the AI writes, catch mistakes, and guide it toward better results.
Knowledge of Luau plus AI assistance is a force multiplier. Learn the basics. Let AI handle the volume.
Ready to build?
5 free credits. No card required. Start building in Roblox Studio with AI.
Try Rebirth free