ESX Legacy for FiveM: what it is, common mistakes and the AI skill
Updated
Don’t want to manage skills yourself? Get the full app.
ESX Legacy is the long-running FiveM roleplay framework built around xPlayer, jobs, accounts and inventory. This guide covers its core API, the mistakes that break ESX scripts and the AI skill that writes code against the real API.
ESX Legacy is the framework that runs a large share of FiveM roleplay servers: it manages players, jobs, money, inventory and weapons through the es_extended resource. If you write scripts for an ESX server, you talk to it through the ESX object, the xPlayer object on the server and PlayerData on the client. This page explains what the ESX skill for FiveAI covers, the mistakes that break ESX scripts most often, and how to install the skill in your AI assistant.
Quick reference
Most searched ESX Legacy calls. Server calls need a nil check on xPlayer.
| Call | Side | What it does |
|---|---|---|
ESX.GetPlayerFromId(source) |
Server | Returns the xPlayer for a player, or nil |
ESX.GetPlayerFromIdentifier(identifier) |
Server | Finds a player by identifier |
ESX.GetExtendedPlayers(key, value) |
Server | Players matching a filter such as 'job', 'police' |
xPlayer.getMoney() / addMoney(amount, reason) / removeMoney(amount, reason) |
Server | Cash |
xPlayer.getAccount(name) / addAccountMoney(account, amount, reason) |
Server | Accounts such as bank |
xPlayer.getJob() / setJob(name, grade, onDuty) |
Server | Job data and job changes |
xPlayer.addInventoryItem(item, count) / removeInventoryItem(item, count) |
Server | Items |
ESX.RegisterServerCallback(name, cb) |
Server | Answer a client request; the handler gets source, cb, ... |
ESX.TriggerServerCallback(name, cb, ...) |
Client | Ask the server for data |
ESX.IsPlayerLoaded() / ESX.PlayerData |
Client | Check the player loaded before reading data |
What the ESX skill gives you
The skill is a SKILL.md file with rule files for each part of the framework:
core-concepts: howes_extendedinitializes, whatPlayerDataholds on the client and whatxPlayerholds on the server.client-functionsandserver-functions:ESX.IsPlayerLoaded()andESX.PlayerDataon the client,ESX.GetPlayerFromId(source)on the server, callbacks and triggers.xplayer-methods: the methods for money, items, weapons, inventory, jobs and metadata.jobs-economy: job definitions, salaries, themoneyandbankaccounts, society management.inventory-itemsandweapons-loadout: item registration, usable items, weight, weapons, components, ammo and tints.events-callbacks: ESX events, server and client callbacks, andSecureNetEventfor events that clients trigger.best-practices: nil checks, caching player objects, camelCase naming, few globals, and ox_lib for menus, notifications and progress bars instead of the ESX UI.
Use it when you create an ESX resource, add a job, touch the economy or write anything that reads player data.
Common mistakes with ESX
- Using
xPlayerwithout a nil check. Symptom: "attempt to index a nil value" in the server console when a player disconnects mid-event or the source is invalid. Fix:local xPlayer = ESX.GetPlayerFromId(source)followed byif not xPlayer then return end. - Mixing ESX and QBCore APIs. Symptom:
QBCore.Functions.GetPlayeror aPlayer.Functions.AddMoneycall inside an ESX script, and a nil error at runtime. This happens when a script was copied from a QBCore tutorial. Fix: useESX.GetPlayerFromIdand thexPlayermethods, nothing else. - Reading
ESX.PlayerDatabefore the player is loaded. Symptom: empty job or money fields on the client during the first seconds after spawn. Fix: checkESX.IsPlayerLoaded()or wait for the player loaded event before readingPlayerData. - Trusting money amounts from the client. Symptom: a cheater triggers your event with a custom amount and the server pays it. Fix: compute prices and rewards on the server, validate the source and use
SecureNetEventfor client-triggered events. - Calling
ESX.GetPlayerFromIdinside loops. Symptom: a server thread that ticks every frame and looks up the same player each iteration. Fix: getxPlayeronce, keep it in a local, and reuse it.
Why AI assistants get ESX wrong
A generic assistant has seen years of ESX tutorials, and many of them target old versions. It will often reach for the esx:getSharedObject event to obtain the ESX object, invent methods that do not exist on xPlayer, or put server-only logic in a client file. It also mixes framework vocabulary: xPlayer in one function, Player.PlayerData in the next, because both appear in its training data.
The skill gives the assistant a short, current reference instead. Older tutorials use the getSharedObject event; ESX Legacy provides the object through the es_extended import or export, and the skill's core concepts file points the assistant to that. The principles list (check nil, wait for player load, never trust the client, cache player objects, prefer ox_lib for UI) is loaded every time you ask for ESX code, so the output matches the API your server runs.
To see how a skill compares with other FiveM AI setups, read our comparison.
Install the ESX skill in 30 seconds
- Click "Download SKILL.md" at the top of this page.
- Unzip it into your AI tool's skills or rules folder. The install section below shows the exact path for Claude Code, Cursor and VS Code.
- Ask the assistant for something concrete, such as a server event that removes an item and adds money to the
bankaccount, and check that it usesESX.GetPlayerFromIdwith a nil check.
How to install this skill
Download the zip, unzip it, and place the folder where your tool loads skills or rules. The exact path depends on the tool:
Claude Code
Unzip into .claude/skills/esx-framework/ inside the project (the folder must contain SKILL.md). For every project, use ~/.claude/skills/esx-framework/ instead.
Cursor
Cursor loads project rules from .cursor/rules/. Add a rule file there that points to the unzipped skill, or paste the contents of SKILL.md and the rule files into a rule. The format is .mdc with frontmatter and changes between versions, so check the docs for your version.
VS Code / Copilot
Copilot reads instruction files from .github/instructions/*.instructions.md. Copy SKILL.md there with an applyTo glob for your Lua files, and keep the rule files next to it.
The SKILL.md file
This is the file your AI assistant reads. It links to the rule files bundled in the download.
ESX Framework Development
Complete guide for developing with ESX Legacy Framework — the most trusted FiveM roleplay framework since 2017.
When to use
- Creating or editing ESX resources/scripts
- Working with player data (xPlayer, PlayerData)
- Implementing jobs, economy, inventory, or weapon systems
- Using ESX client/server functions, callbacks, or events
- Questions about ESX best practices and optimization
How to use
Read individual rule files for detailed explanations and examples:
rules/core-concepts.md — ESX architecture, PlayerData, xPlayer object, framework initialization
rules/client-functions.md — Client-side ESX functions, UI systems, player state management
rules/server-functions.md — Server-side functions, player retrieval, callbacks, triggers
rules/xplayer-methods.md — xPlayer object methods: money, items, weapons, inventory, jobs, metadata
rules/jobs-economy.md — Job system, salaries, accounts (money/bank), society management
rules/inventory-items.md — Inventory system, item management, usable items, weight calculations
rules/weapons-loadout.md — Weapon system, loadout, components, ammo, tints
rules/events-callbacks.md — ESX events, server callbacks, client callbacks, secure net events
rules/best-practices.md — ESX coding standards, optimization, security, naming conventions
rules/reference-links.md — Official ESX documentation links
Key principles
- Always check for nil —
if xPlayer then ... endbefore using xPlayer - Use ESX.GetPlayerFromId — Standard player retrieval:
local xPlayer = ESX.GetPlayerFromId(source) - Wait for player load — Check
ESX.IsPlayerLoaded()on client before accessing PlayerData - Never trust client — Validate all data server-side, use SecureNetEvent for client events
- Follow ESX patterns — Use ESX functions instead of reinventing (callbacks, notifications, etc.)
- Optimize loops — Cache player objects, avoid unnecessary GetPlayerFromId calls
- Use camelCase — Follow Lua naming:
myVariable,MyGlobalFunction,MY_CONSTANT - Minimal globals — Keep variables local unless they need global scope
- Use ox_lib for UI — Prefer ox_lib for menus, dialogs, notifications, progress bars instead of ESX UI
Frequently asked questions
- Both are valid. ESX is the older framework and is still widely used, with a large catalog of compatible scripts. QBCore has a different API and its own ecosystem. Pick the one your team knows and whose scripts you plan to run, and do not mix APIs in one resource.
- Yes. The skill documents the current ESX Legacy API: ESX.GetPlayerFromId, xPlayer methods, ESX.IsPlayerLoaded, server callbacks and SecureNetEvent. Old ESX 1.1 or 1.2 patterns are not the target.
- Yes. SKILL.md is plain markdown. Paste it as a custom instruction or attach it to a project in ChatGPT. Claude Code, Cursor and VS Code load it directly from their skills or rules folder.
Should I pick ESX or QBCore for a new server?
Does this skill cover ESX Legacy only?
Can I use this skill with ChatGPT?
Related guides
Longer reads from the FiveAI blog on the same topic.