Roblox Scripting Master Guide (Lua)
1. Introduction to Scripting in Roblox
Roblox scripting uses the Lua programming language to create game logic
and interactivity. This guide will walk you through all the fundamental and
advanced concepts.
2. Basic Data Types
Type Example Description
nil local a = nil Absence of a value
boolean true, false True or false
number local x = 5.5 Any number (integer or
decimal)
string "Hello" Text enclosed in quotes
function function greet() Code block you can call
table {1, 2, 3} Array/dictionary
userdata Roblox objects like Instance Roblox-specific types
Vector3 Vector3.new(0, 1, 0) 3D position
CFrame CFrame.new(0, 0, 0) 3D position + rotation
Color3 Color3.new(1, 0, 0) RGB Color
BrickColo BrickColor.new("Bright Predefined color
r red")
Enum Enum.Material.Wood Roblox enumeration
3. Variables
local name = "Daksh"
local age = 15
local isOnline = true
4. Conditionals
if age > 13 then
print("Teenager")
elseif age == 13 then
print("Just turned teen!")
else
print("Child")
end
5. Loops
-- For loop
for i = 1, 5 do
print(i)
end
-- While loop
local n = 0
while n < 5 do
print(n)
n += 1
end
6. Functions
function greet(name)
print("Hello, " .. name)
end
greet("Daksh")
function add(a, b)
return a + b
end
7. Tables
local playerStats = {
name = "Daksh",
score = 100,
online = true
}
print(playerStats.name)
8. Events
script.Parent.Touched:Connect(function(hit)
print("Touched!")
end)
9. Services
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined the game")
end)
10. Remote Events & Functions
Server Script:
game.ReplicatedStorage.MyEvent.OnServerEvent:Connect(function(player,
message)
print(player.Name .. " says: " .. message)
end)
Client Script:
game.ReplicatedStorage.MyEvent:FireServer("Hello!")
11. ModuleScripts
Module:
local module = {}
function module.sayHi()
print("Hi from Module")
end
return module
Usage:
local myModule = require(game.ServerScriptService.MyModule)
myModule.sayHi()
12. Object-Oriented Programming (Advanced)
Lua can simulate OOP using metatables. (Advanced topic, explained later.)
More Coming Soon:
Tweening
Raycasting
Datastore saving
GUIs and UI scripting
Animations
Tools & weapons
Stay tuned and keep practicing! 💡