Skip to main content
TRACK B·PRODUCTION ENGINEERING·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

Exports: sharing functions across resources

An export lets one resource borrow a function from another and get an answer back. That is the whole idea. Events fire and forget; exports are real function calls, so they run instantly and hand you a return value. This is how every framework wires its pieces together: exports.ox_inventory:GetItemCount, exports.es_extended:getSharedObject. Here is the deal: you will publish a function in one resource and then call it from a second one, so you actually see the cross-resource call this lesson is named for.

You'll learn
exports('name', fn) registration, exports.resource:fn() call syntax, why exports are synchronous and same-side, the global-namespace risk, and when to reach for an event instead
Time
~18 minutes
Prereqs
Lessons 13 & 14 (events)
Outcome
You can build a money resource a second resource reads from with exports.qu_money:GetBalance(src), and explain why it is a real function call and not an event
BEFORE YOU START

Build it

Make the two resource folders

The server has one folder per resource.

Inside your server's resources folder, create both of these folders:

code
resources/qu_money
resources/qu_money_consumer

Create the files

Every file named in each manifest exists.

Create this exact file layout:

code
resources/qu_money/
fxmanifest.lua
server.lua
resources/qu_money_consumer/
fxmanifest.lua
server.lua

Write qu_money/fxmanifest.lua

FiveM knows which files to load for the provider.

Open qu_money/fxmanifest.lua and paste this:

code
fx_version 'cerulean'
game 'gta5'

server_script 'server.lua'

Write qu_money/server.lua

The provider exposes two functions as exports.

Open qu_money/server.lua and paste this:

code
local balances = {}

local function getBalance(src)
balances[src] = balances[src] or 0
return balances[src]
end

local function addBalance(src, amount)
balances[src] = getBalance(src) + amount
return balances[src]
end

exports('GetBalance', getBalance)
exports('AddBalance', addBalance)

Write qu_money_consumer/fxmanifest.lua

The consumer declares it depends on the provider.

Open qu_money_consumer/fxmanifest.lua and paste this:

code
fx_version 'cerulean'
game 'gta5'

dependencies {
'qu_money'
}

server_script 'server.lua'

Write qu_money_consumer/server.lua

The consumer calls the provider's export by name.

Open qu_money_consumer/server.lua and paste this:

code
RegisterCommand('checkmoney', function(src)
exports.qu_money:AddBalance(src, 50)
local balance = exports.qu_money:GetBalance(src)
print('[qu_money_consumer] player ' .. src .. ' balance ' .. balance)
end, true)

Start and test it

The cross-resource call prints the expected proof.

Open server.cfg and add both lines, provider first:

code
ensure qu_money
ensure qu_money_consumer

Save. If this is the first time you are loading these resources, start them with ensure (provider first); restart only works on a resource that is already running. Run these in the txAdmin Live Console:

code
ensure qu_money
ensure qu_money_consumer

Later, after you edit a file, re-load with restart qu_money then restart qu_money_consumer.

Run this test from the txAdmin Live Console:

code
checkmoney

The 0 is the server console's source id (the console is always player 0). The 50 is the value that came back across the resource boundary from qu_money. Run checkmoney again and the balance climbs to 100, then 150. The number persists because both calls read and write the same balances table living inside qu_money.

Keep reading the full lesson

Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.

Still ahead in this lesson
  • How it works
  • If something went wrong
  • What you can do now
  • Try it yourself

The remainder of Exports across resources is available to FiveM School members.