What is Lua?
Lua is a lightweight, high-level scripting language designed for embedded use in applications. RedM (and FiveM) use Lua 5.4 as their primary scripting language for creating game modifications and server resources.Lua is easy to learn, fast to execute, and powerful enough to create complex game systems. It’s the perfect language for RedM development!
Client vs Server Scripts
RedM resources can have client scripts, server scripts, or both. Understanding the difference is crucial:Client Scripts
- Run on each player’s machine independently
- Handle visual effects, UI, local player actions
- Cannot directly access server data or other players
- File location:
client/folder or defined asclient_scriptin fxmanifest.lua
Server Scripts
- Run once on the server
- Handle game logic, database operations, player data
- Manage communication between players
- File location:
server/folder or defined asserver_scriptin fxmanifest.lua
Shared Scripts
- Run on both client and server
- Used for shared configurations, item definitions, etc.
- File location:
shared/folder or defined asshared_scriptin fxmanifest.lua
Clients cannot communicate directly with each other. All communication must go through the server using events.
Basic Lua Syntax
Variables
Data Types
Comments
Functions
Defining Functions
Anonymous Functions
Control Structures
If Statements
Loops
Tables (Arrays & Dictionaries)
Tables are Lua’s primary data structure - they can act as arrays, dictionaries, or both!Arrays (Numeric Indices)
Dictionaries (Key-Value Pairs)
String Manipulation
Math Operations
Creating Your First Resource
Step 1: Create Resource Folder
Create a folder in yourresources directory:
Step 2: Create fxmanifest.lua
Every resource needs a manifest file:fxmanifest.lua
Step 3: Create Your Scripts
shared/config.lua:Step 4: Start Your Resource
Add toserver.cfg:
Common Mistakes to Avoid
Next Steps
Now that you understand Lua basics, explore these advanced topics:- Events & Callbacks - Communication between client and server
- Threads & Loops - Creating continuous processes
- Table Operations - Advanced table manipulation
- Common Patterns - RSG Framework patterns and best practices
- Performance Tips - Optimize your code
- Debugging - Find and fix errors