Engineering
Exports: calling functions in another FiveM resource
How FiveM exports work: defining exports in Lua, JS and the manifest, calling exports.resource:fn(), client vs server exports, return values, errors like 'No such export', and exports vs events.
Overview
Resources are isolated from each other: a local function in one cannot be called from another. Exports are the bridge — a resource publishes a function by name, and any other resource on the same side can call it and get a return value back. Frameworks and libraries are built on them: exports.ox_inventory:AddItem, exports['qb-core']:GetCoreObject().
Defining an export
local balances = {}
exports('getBalance', function(playerId)
return balances[playerId] or 0
end)
exports('addMoney', function(playerId, amount)
balances[playerId] = (balances[playerId] or 0) + amount
return balances[playerId]
end)Registering with exports() in code is the modern way. Older resources list exported function names in the manifest with export (client) and server_export (server); both still work.
Calling an export
local balance = exports.my_bank:getBalance(source)
exports.my_bank:addMoney(source, 250)
-- Names with dashes need brackets
local QBCore = exports['qb-core']:GetCoreObject()Client and server exports
“No such export” and other errors
| Cause | Fix |
|---|---|
| The resource is not started (yet) | Start it earlier in server.cfg or list it in dependencies |
| Name typo or wrong case | Export names are case-sensitive |
| Wrong side | A server export called from a client script (or the reverse) |
| Called at load time before the other resource registered it | Call inside a function or after a short wait, or use dependencies |
| Resource was renamed | The folder name is the resource name — update the call |
Exports vs events
| Exports | Events | |
|---|---|---|
| Direction | Same side only | Same side or across the network |
| Return value | Yes, directly | No (use callbacks) |
| Coupling | Caller must know the resource name | Loosely coupled by event name |
| Best for | APIs: inventories, frameworks, utilities | Notifications and cross-network messages |
A good resource offers both: exports for other developers to call its API, and events it fires when something happens.
Performance note
Each export call crosses resource boundaries and serialises arguments. Calling one inside a per-frame loop is a common hidden cost. Cache results that do not change often (a framework object, a config) in a local at start-up.
Frequently asked questions
How do I call a function from another resource in FiveM?
The other resource exports it with exports('name', fn); you call it with exports.resourceName:name(...).
What does 'No such export' mean?
The resource is not started, the export name is misspelled, or you are calling it from the wrong side (client vs server).
Can a client call a server export?
No. Exports are same-side. Use an event or a callback to reach the server.
Why do I need brackets in exports['qb-core']?
Lua identifiers cannot contain dashes, so resource names with dashes must use bracket syntax.
Need this built, not just explained?
Ten years of FiveM work, from Lua to NUI
Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.
Related guides
- EngineeringEvents in FiveM: how resources and players talkHandle events with AddEventHandler(name, fn); add RegisterNetEvent(name) (or use RegisterNetEvent(name, fn)) to allow the event to arrive over the network. TriggerEvent fires locally on the same side, TriggerServerEvent sends from a client to the server, and TriggerClientEvent(name, target, ...) sends from the server to one player (target = player ID) or everyone (-1). On the server, source is the sending player.
- FrameworksCallbacks: asking the server a question and getting an answerA callback registers a named handler on one side and lets the other side call it and receive its return value. With ox_lib use lib.callback.register on the server and lib.callback.await on the client (it also works server → client). ESX uses ESX.RegisterServerCallback / ESX.TriggerServerCallback, QBCore QBCore.Functions.CreateCallback / QBCore.Functions.TriggerCallback. Validate inside callbacks exactly like events.
- Getting startedWhat a FiveM resource is, and how the server loads itA resource is a folder inside resources/ containing an fxmanifest.lua. The manifest declares the format (fx_version 'cerulean', game 'gta5'), which scripts run on the client, the server or both, which extra files clients download, and what the resource depends on. The server starts it when server.cfg says ensure foldername.
- FrameworksSupporting several frameworks with a bridgeDetect the running framework with GetResourceState('qbx_core'), ('qb-core') and ('es_extended'), load a matching bridge file, and have every bridge expose the same functions — get player identifier, job, money add/remove, notify, item add/remove. Keep framework calls out of your main logic, allow a config override, and test on each framework you claim to support.