Skip to main content
TRACK B·FIVEM FUNDAMENTALS·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.

Callbacks: ask a question, get an answer

Events are good when you just want to send a message and move on. But some situations need a reply. For example: "do I have enough money to buy this?" In that case the client asks a question, waits, and gets an answer back. That pattern is called a callback.

You'll learn
When to use a callback -> lib.callback.register on the server -> lib.callback.await on the client -> sync vs async forms
Time
~25 minutes
Prereqs
Lessons 13-14 complete. You know TriggerServerEvent, RegisterNetEvent, source.
Outcome
A working "can I afford this?" check, client asks, server verifies against its own balance, client waits for the yes/no and branches.
Callbacks vs events: the server and client round-trip explained.
BEFORE YOU START

Build it

Make the resource folder

The server has one folder for this lesson.

Inside your server's resources folder, create this folder:

code
resources/qu_callbacks

Create the files

Every file named in the manifest exists.

Create this exact file layout:

code
resources/qu_callbacks/
fxmanifest.lua
server.lua
client.lua

Write fxmanifest.lua

FiveM knows which files to load and that ox_lib must load first.

Open fxmanifest.lua and paste this:

code
fx_version 'cerulean'
game 'gta5'

shared_script '@ox_lib/init.lua'
client_script 'client.lua'
server_script 'server.lua'

dependencies {
'ox_lib'
}

The dependencies { 'ox_lib' } block tells the server not to start qu_callbacks until ox_lib is running. The singular form dependency 'ox_lib' is tolerated, but the plural block is the canonical one, so use it. The shared_script '@ox_lib/init.lua' line is what actually loads the library and gives you the global lib on both the client and the server.

Write the lesson code

The client asks a question and the server answers it.

Open server.lua and paste this:

code
lib.callback.register('qu_callbacks:getBalance', function(src)
print('[qu_callbacks] server answering ' .. GetPlayerName(src))
return 500
end)

Open client.lua and paste this:

code
RegisterCommand('mybalance', function()
local balance = lib.callback.await('qu_callbacks:getBalance', false)
print('[qu_callbacks] my balance is ' .. balance)
end, false)

Start and test it

The expected proof appears in the correct console.

Make sure ox_lib starts first. Open server.cfg and add both lines in this order:

code
ensure ox_lib
ensure qu_callbacks

Save. Then, in the txAdmin Live Console (the same place you read server output - not the in-game chat and not your computer's terminal), type:

code
restart qu_callbacks

Join the server, then run this test from the chat box (press T) (this is a client command):

code
/mybalance

You will also see [qu_callbacks] server answering YourName in the txAdmin Live Console, proving the request crossed the network and the server is the one that produced the number.

CLIENT
the player's game
network
SERVER
validate here
✓ trust boundary
A callback is a round trip: the client asks, the server answers. The server still validates the request before replying.

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 Callbacks is available to FiveM School members.