ESXserver
ESX.RegisterServerCallback
ESX server documentation with a FiveM Lua example.
Summary
Registers a server callback in ESX that clients can call and await a value from — ESX's request/response pattern.
Returns
void
Parameters
namestringThe callback name.handlerfunctionfunction(source, cb, ...) — call cb(result) to respond.Example
-- SERVER
ESX.RegisterServerCallback('myscript:getMoney', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
cb(xPlayer.getMoney())
end)
-- CLIENT
ESX.TriggerServerCallback('myscript:getMoney', function(money)
print(money)
end)Common pitfalls
- Always call cb() exactly once or the client waits forever.
- Validate the source server-side; callbacks cross the network boundary.
Related functions
Related guides
FiveM scripts done right
Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.
Browse Scripts →