FiveM Bank Heist Script: QBCore/ESX Setup
This guide walks a builder from system design to a secure FiveM bank heist implementation. It emphasises server authority, framework boundaries (QBCore/ESX/ox_lib), target interactions, anti-cheat validation, and installation notes so you can ship a robust resource.
Overview
A bank heist is a complex multiplayer interaction: multiple players coordinate, timed objectives run, inventory items are consumed, doors unlock, police must be notified, and rewards are distributed. Because these actions affect player economy and persistence, authority must live on the server. This guide explains design choices, includes a server-authoritative code example for QBCore, details how to wire qb-target/ox_lib interactions, and provides a practical checklist for deployment.
Design goals
- Server authority: all state-changing decisions and reward distribution are validated on the server.
- Minimal client trust: clients can request actions but cannot grant themselves rewards or bypass checks.
- Framework agnostic patterns: implementable with QBCore, ESX, or ox_lib by swapping small integration layers.
- Auditability and logging: every heist attempt is logged for moderation and debugging.
- Rate-limited and auditable: cooldowns and per-player concurrency limits to deter farming.
High-level flow
- Player approaches vault and uses qb-target/ox_lib to trigger a heist attempt.
- Client fires a safe server event asking to start the heist; server verifies prerequisites (police online, item requirements, cooldowns, job restrictions).
- Server reserves the vault (locks it) and notifies all clients to start synchronized animations/timers.
- During the heist, server-side timers validate progress; anti-cheat checks watch for impossible state changes.
- At completion, server awards loot (cash, items) and logs the transaction; failure triggers cleanup and cooldowns.
Server authority & validation (must-haves)
All critical checks occur on the server. Do not accept client claims about item removals or task completion. Example validations:
- Check police count server-side with an authoritative player list.
- Verify and consume required items from the player inventory with framework APIs (QBCore:
QBCore.Functions.GetPlayer, ESX:xPlayer). - Use database flags or in-memory locks to reserve the vault during an ongoing heist.
- Use server-side timers and verify heartbeats from clients, but treat them as hints — don’t grant rewards without final server checks.
Common server-side checks
- Active heist flag: is the vault already in progress?
- Whitelist/exclusion: is the player allowed to initiate? (jobs, bans)
- Cooldowns: last completed attempt time per player and per-vault cooldown.
- Item/skill verification: confirm removal of physical items or craft requirements.
QBCore / ESX / ox_lib boundaries
Design your resource with a small integration layer so that the core logic is framework-agnostic. Provide adapter functions for inventory ops, job checks, and notifications.
- QBCore: use
QBCore.Functions.GetPlayer,player.Functions.RemoveItem, and exports for logging. - ESX: use
xPlayermethods likexPlayer.removeInventoryItemand server callbacks. - ox_lib: use its notification and lib callbacks; for target interactions use
ox_targetif present.
Client ↔ Server separation and qb-target
Clients only trigger an intent. Use qb-target or ox_target to start the interaction; client code should only display prompts and animations. Example target action: client triggers heist:server:tryStart. The server responds with confirmations or errors.
QBCore server-side validation example (safe starting point)
This illustrative server-side snippet checks a server-owned vault ID, the player, location and police count before any start logic. It deliberately gives no rewards. Define vault coordinates in your server config, then implement inventory checks, cooldowns and server-verified objective completion before putting it into production.
-- server.lua: validation skeleton, NOT a complete heist resource
local QBCore = exports['qb-core']:GetCoreObject()
local activeVaults = {}
RegisterNetEvent('heist:server:tryStart', function(vaultId)
local src = source -- capture before callbacks or waits
if type(vaultId) ~= 'string' then return end
local vault = Config.Vaults and Config.Vaults[vaultId]
if not vault or not vault.coords then return end
if activeVaults[vaultId] then return end
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local ped = GetPlayerPed(src)
if not ped or ped == 0 then return end
if #(GetEntityCoords(ped) - vault.coords) > 4.0 then return end
local policeOnline = 0
for _, playerId in ipairs(QBCore.Functions.GetPlayers()) do
local p = QBCore.Functions.GetPlayer(playerId)
local job = p and p.PlayerData and p.PlayerData.job
if job and job.name == 'police' and job.onduty then
policeOnline = policeOnline + 1
end
end
if policeOnline < (Config.RequiredPolice or 0) then return end
-- NEXT: verify item requirements and cooldowns on the server.
-- NEXT: reserve the vault atomically and log the start.
-- NEVER award loot merely because a timer elapsed.
-- Rewards require verified server-side completion and replay protection.
end)
Why this matters: simply waiting for SetTimeout and then calling AddMoney is not proof of completing a heist. A reliable resource needs one-time completion state, server-side distance and objective checks, reconnect/abort handling, and reward accounting that cannot be replayed. A network event by itself does not authorize a payout. See the official Cfx.re event-security guidance.
Anti-cheat and validation strategies
- Never trust client-submitted progress, finish signals or reward amounts. Only pay after server-authoritative objective validation, and make completion idempotent so rewards cannot be replayed.
- Apply per-player and per-vault cooldowns, and log repeated invalid attempts for review.
- Use server-side position checks if necessary: confirm the starter is near the vault when finishing.
- Use explicit per-event input and permission checks. Registering a network event allows remote calls; it does not make requests trustworthy.
Persistence, logging, and economics
Keep a heist_logs table with starter id, participants, timestamp, vault id, and reward. This aids rollback and moderation. Ensure reward values are balanced and server-side configurable via config.lua, and avoid hard-coding large sums in client files.
Deployment checklist
| File | Purpose |
|---|---|
| fxmanifest.lua | Resource manifest and dependency declarations (qb-core, qb-target, oxmysql) |
| config.lua | All tunables: police requirement, cooldowns, rewards |
| server.lua | Server authority logic, DB writes, validation |
| client.lua | qb-target/ox_lib interaction, animations, UI |
| sql/ | Schema for heist_logs and any persistence |
Quick installation notes
- Declare dependencies in fxmanifest (e.g.,
dependency 'qb-core'). - Install SQL schema and verify oxmysql/ghmattimysql connectivity.
- Tune Config.RequiredPolice and Config.HeistDuration on a test server before live.
- Test with staff accounts or a private server then roll to staging.
Testing and monitoring
Test heists with multiple clients, ensure cooldowns are enforced, and deliberately attempt invalid flows (missing items, insufficient police) to ensure server responses are robust. Monitor logs for rapid repeat attempts and unexpected DB errors. For team workflows, use the Stellar AI app to sketch the resource's states and file outputs, then iterate on implementation — you can start a new project at https://trystellarai.com/app or open the app later when designing variants at https://trystellarai.com/app.
Further reading
For patterns and community discussions about resource structure and security, check the project writing on the Stellar AI blog: https://trystellarai.com/blog. Also consult core docs for QBCore, ESX, qb-target, and your chosen MySQL wrapper when wiring production code.
Practical launch checklist
- Run unit smoke tests on server-side checks: police count, item removal, cooldowns.
- Deploy to staging; run multi-client heist stress tests with logging enabled.
- Verify DB inserts and ensure no sensitive keys are in code or logs.
- Review and set event whitelists; ensure only expected resources can call your server events.
- Document admin commands for forced cleanup and logs retrieval.
Related guides
- FiveM Bank Robbery Script — QBCore Guide
- FiveM Heist Scripts — What You Need to Know
- FiveM Drug Dealer Script — Safe Design Guide
- QBCore ATM Robbery — Secure Implementation
Want it fixed for you? The £99 Priority Script Fix is a one-off fix for a FiveM or Roblox script. Memberships start at £8 a month on the plans page.
Related tools: FiveM script generator · Fix a FiveM Lua error · all script generators