New to Roblox Studio scripting? This beginner guide covers Luau basics, where to put scripts, and your first working scripts with copy-paste examples.
Roblox uses Luau โ a fast, typed dialect of Lua 5.1 developed by Roblox. If you've seen Lua tutorials online, most of it applies to Roblox scripting too.
This is the most confusing part for beginners. There are three main places:
ServerScriptService โ Scripts here run on the server. Use these for game logic, saving data, handling purchases, and anything security-sensitive. Players cannot see or edit these.
StarterPlayerScripts โ LocalScripts here run on each player's computer. Use these for GUIs, input handling, and visual effects.
StarterGui โ LocalScripts for your GUI elements go here.
Inside Parts โ You can put a Script directly inside a Part in the workspace. Good for simple things like kill bricks.
Put a Script inside a Part in the workspace:
local part = script.Parent
local light = Instance.new("PointLight")
light.Brightness = 5
light.Range = 20
light.Parent = partscript.Parent refers to whatever the script is inside โ in this case, the Part.
local playerName = "Alex" -- string local score = 100 -- number local isAlive = true -- boolean local nothing = nil -- nil (empty/no value)
Always use local for variables. Global variables in Roblox can cause hard-to-find bugs.
local score = 50
if score >= 100 then
print("You win!")
elseif score >= 50 then
print("Almost there!")
else
print("Keep going!")
endlocal function greetPlayer(player)
print("Welcome, " .. player.Name .. "!")
end
game.Players.PlayerAdded:Connect(greetPlayer)... joins strings together. :Connect() wires an event to a function โ so every time a player joins, greetPlayer runs.
-- Repeat 5 times
for i = 1, 5 do
print("Count: " .. i)
end
-- Loop forever (use task.wait to avoid lag)
while true do
task.wait(1)
print("One second passed")
endAlways use task.wait() in while loops. A loop without a wait will freeze Roblox Studio instantly.
Almost everything in Roblox goes through services:
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local DataStoreService = game:GetService("DataStoreService")Lowercase API names โ Roblox APIs are case-sensitive. findFirstChild won't work, FindFirstChild will.
Missing nil checks โ Always check if something exists before using it. if player.Character then before accessing the character.
Script in the wrong place โ If your script isn't working, check where it is. A LocalScript in ServerScriptService won't run. A regular Script in StarterGui won't work either.
Once you're comfortable with the basics, check out our free script library. Copy working scripts, read through them, and modify them for your game. Learning by editing real code is faster than any tutorial.
Browse our free library of copy-paste Luau scripts โ no setup needed.
Browse Script Library โ