Skip to main content
The Callbacks component provides a request-response pattern for communication between client and server, allowing one side to request data from the other and receive a response.
Important: The component name is Callbacks (plural), not Callback (singular).

Overview

Callbacks solve the problem of asynchronous request-response communication in FiveM, where events are one-way.

Request-Response

Ask for data and receive a response

Bi-Directional

Client → Server or Server → Client

Type-Safe

Structured data exchange

Auto-Cleanup

Callbacks removed after execution

Server-Side Methods

RegisterServerCallback

Register a callback that clients can invoke. Signature:
Parameters: Callback Parameters:
  • source (number) - Player source who triggered callback
  • data (any) - Data sent from client
  • cb (function) - Response function to call with results
Example:

ClientCallback

Send a callback request to a client and receive response. Signature:
Parameters: Example:

Client-Side Methods

ServerCallback

Send a callback request to server and receive response. Signature:
Parameters: Example:

RegisterClientCallback

Register a callback that server can invoke. Signature:
Parameters: Callback Parameters:
  • data (any) - Data sent from server
  • cb (function) - Response function to call with results
Example:

ExtraId Parameter

The extraId parameter prevents callback conflicts when the same event is triggered multiple times simultaneously. Without extraId (can cause conflicts):
With extraId (safe):
When to use:
  • Multiple simultaneous calls to same callback
  • Loops that trigger callbacks
  • Rapid successive calls
Example:

Complete Examples

Character Data Request

Server:
Client:

Inventory Check

Server:
Client:

Vehicle Spawn Request

Server:
Client:

Shop Purchase

Server:
Client:

Client-to-Server Notification

Client (Register):
Server (Request):

Best Practices

Check for errors in callback responses:
Name callbacks by resource and action:
Always validate callback data:
Prevent callback conflicts in loops:

Troubleshooting

Callback Not Firing

  1. Check component name:
    • Use Callbacks (plural), not Callback
  2. Verify callback is registered:
    • Server callbacks must be registered before client calls them
    • Register callbacks in resource startup, not in event handlers
  3. Check event names match exactly:

Getting Wrong Data

  1. Use extraId for disambiguation:
    • Multiple simultaneous calls need unique extraIds
  2. Check callback cleanup:
    • Callbacks auto-delete after execution
    • Don’t reuse the same callback multiple times

Timeout Issues

  1. Callbacks timeout if no response:
    • Always call cb() in your handler
    • Don’t forget callback in async operations:

Next Steps

Core - Fetch

Player and character data access

Core - Logger

Logging system

Events System

Understanding events

Middleware

Event middleware
Pro Tip: Create wrapper functions for common callbacks to reduce boilerplate: