Skip to main content

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 as client_script in 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 as server_script in fxmanifest.lua

Shared Scripts

  • Run on both client and server
  • Used for shared configurations, item definitions, etc.
  • File location: shared/ folder or defined as shared_script in fxmanifest.lua
Clients cannot communicate directly with each other. All communication must go through the server using events.
Example Flow:

Basic Lua Syntax

Variables

Always use local variables unless you specifically need a global variable. Global variables can cause conflicts and performance issues.

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 your resources directory:

Step 2: Create fxmanifest.lua

Every resource needs a manifest file:
fxmanifest.lua

Step 3: Create Your Scripts

shared/config.lua:
client/client.lua:
server/server.lua:

Step 4: Start Your Resource

Add to server.cfg:
Or start it in-game:

Common Mistakes to Avoid

1. Forgetting local keyword
2. Array indexing starts at 1, not 0
3. Using == for string/table comparison
4. Not checking for nil

Next Steps

Now that you understand Lua basics, explore these advanced topics:
Practice makes perfect! Start with simple scripts and gradually add complexity as you learn.