FiveM Lua Obfuscator – Protect Your FiveM Scripts
Protect your FiveM resource scripts with compile-safe obfuscation: local identifier renaming, string encoding with round-trip verification, and comment stripping — built for CfxLua 5.4 with backtick hash preservation.
This tool performs only transformations that cannot break your FiveM script: local variable renaming (self is never renamed), string encoding in safe contexts (round-trip verified), comment removal, and whitespace minification. CfxLua backtick hashes (`adder`) are preserved as opaque atoms. CitizenFX natives, built-in libraries (json, promise, msgpack), and vector constructors are never renamed. Obfuscation is a deterrent, not encryption — never embed real secrets in client scripts.
#!/usr/bin/env bash
# verify-obfuscation.sh — confirm obfuscated FiveM Lua parses correctly.
#
# The CfxLua runtime cannot run outside a FiveM server, so this script
# validates syntax using lua5.4 or luac, then diffs output with a
# pure-Lua stub for the CitizenFX globals.
set -euo pipefail
ORIG="${1:-original.lua}"
OBF="${2:-obfuscated.lua}"
if [ ! -f "$ORIG" ]; then echo "Original not found: $ORIG" >&2; exit 1; fi
if [ ! -f "$OBF" ]; then echo "Obfuscated not found: $OBF" >&2; exit 1; fi
LUA=""
for cand in lua5.4 lua54 lua; do
if command -v "$cand" >/dev/null 2>&1; then LUA="$cand"; break; fi
done
if [ -z "$LUA" ]; then
echo "No Lua 5.4 interpreter found. Install lua5.4." >&2
exit 1
fi
echo "Using interpreter: $LUA"
echo "=== Syntax check ==="
"$LUA" -e "assert(loadfile('$ORIG'))" && echo "original: OK"
"$LUA" -e "assert(loadfile('$OBF'))" && echo "obfuscated: OK"
echo ""
echo "=== Note ==="
echo "Full runtime testing requires a running FiveM server."
echo "Syntax check passed for both files."
client_scripts) and server scripts (in server_scripts) both run without changes to output.
FiveM and Cfx.re Rules You Must Follow
Obfuscation is legal and useful on your own FiveM resources. But Cfx.re has explicit rules about how obfuscated code can be distributed on their platform.
When Obfuscation Is the Right Choice
- Protecting your own FiveM resource scripts (client and server) that you distribute on the Cfx.re forum or a personal store.
- Commission work where the client has not paid for source rights.
- Protecting internal tooling and admin scripts distributed to your team.
- Protecting proprietary frameworks, anti-cheat logic, or licensing systems.
When It Is Not
- Hiding backdoors, miners, or unauthorized network calls — this will get your resource removed and your account banned.
- Hiding behavior from Cfx.re moderators or antivirus scanners.
- Anything where the code is not yours to modify.
FiveM-Specific Protection Features
- Backtick hashes (
`adder`) are preserved as opaque atoms. These compile to Jenkins hashes at compile time — modifying them breaks the resource silently. - CitizenFX natives (
Citizen,Wait,CreateThread,TriggerEvent, etc.) are in the reserved set and never renamed. - Built-in libraries (
json,promise,msgpack) are reserved. - First-class vectors (
vector2,vector3,vector4) are reserved.
FiveM Lua obfuscation is the process of transforming a CfxLua (Lua 5.4) script into a functionally equivalent but harder-to-understand form. For FiveM resource developers, it answers a specific problem: client-side scripts ship to every player's machine, where they can be read, modified, and even republished under a different name. This guide explains what obfuscation actually does for FiveM, what it cannot do, and how to use it without breaking your resource or violating Cfx.re's platform rules.
On This Page
Why FiveM Scripts Need Protection
FiveM resources are distributed as plain .lua files (and fxmanifest.lua). When a player connects to your server, the client scripts are downloaded to their machine in readable form. Anyone can open them, study your game logic, extract your API endpoints, or copy your framework wholesale.
Two delivery modes:
- Server-side scripts (
server_scripts) — these run on your server. Players never see them. Obfuscation provides little value here because the code never leaves your infrastructure. - Client-side scripts (
client_scripts) — these ship to every connected player. Obfuscation is meaningful protection here.
If your sensitive logic can run server-side, do that first — it's stronger than obfuscation. Use obfuscation only for logic that must run on the client.
What This Obfuscator Does
Local Identifier Renaming
The tokenizer identifies every local binding, every function parameter, every for loop variable, and every closure parameter. It renames them and updates every reference. Globals, table fields, and CitizenFX natives are never touched.
String Encoding with Round-Trip Verification
String literals in safe contexts are XOR-encoded with a per-build key and a pure-Lua runtime decoder is prepended. Every encoded string is decoded in the browser and compared byte-for-byte to the original. A single mismatch rejects the output.
Comment and Whitespace Removal
Line comments (--) and block comments (--[[ ]]) are stripped safely. Optional whitespace minification reduces file size without changing statement boundaries.
CfxLua-Specific Protections
FiveM uses a modified Lua 5.4 called CfxLua with several unique features that a standard Lua obfuscator would break:
| Feature | How the Tool Handles It |
|---|---|
Backtick hashes (`adder`) | Treated as opaque atoms. Never renamed, never encoded. These compile to Jenkins hashes and modifying them silently breaks the resource. |
| CitizenFX natives | Reserved set includes Citizen, Wait, CreateThread, TriggerEvent, RegisterNetEvent, and ~40 more. |
| Built-in libraries | json, promise, and msgpack are reserved and never renamed. |
| First-class vectors | vector2, vector3, vector4 (and their vec* aliases) are reserved. |
self in methods | Never renamed. Colon-method syntax binds self implicitly; renaming breaks every method body. |
What It Refuses to Do
| Construct | Status | Reason |
|---|---|---|
self | Never renamed | Implicit method receiver — renaming breaks every method body |
| Backtick hashes | Preserved verbatim | Compile-time Jenkins hashes |
| CitizenFX natives | Reserved | Engine API |
| Global variables | Never renamed | Engine API surface |
Table field names (t.field) | Never renamed | Dynamic access |
Metatable keys (__index) | Never renamed | Runtime lookup by exact name |
Strings in require | Not encoded | Module paths must resolve |
Strings in load / loadstring | Not encoded | They are code, not data |
| Numeric literals | Not encoded | Lua precision and coercion |
| Actual encryption | Not claimed | XOR is reversible |
FiveM and Cfx.re Rules
FiveM's Platform License Agreement and Cfx.re Community Guidelines prohibit:
- Uploading resources with obfuscated code intended to hide malicious behavior.
- Hiding backdoors, miners, telemetry, or unauthorized data collection behind obfuscation.
- Using obfuscation to bypass moderation or deceive users about what the resource does.
Honest Limits of Obfuscation
| Goal | Obfuscation helps? | Better approach |
|---|---|---|
| Stop casual copying | Yes, significantly | — |
| Stop a determined reverse engineer | No | Keep critical logic server-side |
| Hide API keys | No | Server proxy; never ship keys |
| Protect licensing checks | Partially | Server-side validation via Cfx.re events |
| Prevent resource theft | Raises the cost | Legal DMCA plus server-side logic |
Recommended Workflow
- Decide what must run client-side. Move everything else to server scripts.
- Obfuscate the client script. Confirm every string passed round-trip verification.
- Copy the output into your FiveM resource's
client_scriptsdirectory. - Test on a local FiveM server. Check the F8 console for client errors.
- For server scripts, run the same obfuscation if you want consistency, but understand it provides little protection (code never leaves your server).
- Only ship after testing on a live server with real players.