Skip to main content
TRACK B·BUILD REAL PRODUCTS·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.

Build a Player-to-Player Trade System

A trade lets two players hand items to each other in the world: you offer 5 bandages, they accept, the items move. The hard part is not the menu - it is making the swap impossible to cheat. This lesson builds a trade where the server owns every decision, both players must confirm, and a lock stops the classic "accept twice and duplicate the item" exploit.

Difficulty
Intermediate
Time
60-90 min
Framework
QBCore / ESX / Qbox
Stack
ox_inventory + ox_lib
Quasar School: building the trade system end to end.
BEFORE YOU START

The mental model: who is allowed to decide what

Before any code, get this picture straight, because it is the whole lesson.

In FiveM there are two worlds. The client is each player's own game - it runs on their PC, and a cheater can rewrite anything it sends. The server is the one machine you control. The rule that keeps every economy script safe is one sentence:

The client may ask. Only the server may decide and act.

A trade has two people. Call them the initiator (the one who runs the command) and the target (the one who receives the request). The dangerous version - the one the old guide taught - let the client say "give me 50 gold from player 12." The server believed it. That is a free money printer.

Here is what the server must verify itself, never trusting the client's word:

  • Does the initiator actually own the item and amount they are offering? Ask the inventory, do not trust the menu's number box.
  • Are the two players close enough to trade? Measure the distance server-side so nobody trades across the map.
  • Did both players confirm? A trade is an agreement, not a one-sided grab.
  • Is this trade already being processed? Lock it so a double-click cannot run the swap twice (that is how duplication bugs happen).

Everything below is built around those four checks. The NUI menu is just a polite way to collect a "yes" - it never moves an item.

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
  • Build it
  • How it works - every decision, and why
  • Failure modes and recovery
  • Checkpoint
  • Exercise

The remainder of Player-to-player trade system is available to FiveM School members.