Giving weapons to players in FiveM, the right way for your server
On a framework server, give weapons through the inventory from the server: exports.ox_inventory:AddItem(source, 'WEAPON_PISTOL', 1) for ox_inventory, Player.Functions.AddItem for QBCore’s default inventory, or xPlayer.addWeapon on ESX. Only on a standalone server should you call GiveWeaponToPed directly. A weapon given only on the client is not saved and is exactly what anticheat looks for.
“How do I give a player a gun?” has four correct answers depending on your server, and one wrong answer that works right up until it gets your players kicked. On a server with an inventory, the weapon has to exist as an item the server knows about; on a standalone server a native is enough. This guide shows each case with code you can paste.

#Which method your server needs
| Server type | Give weapons with | Saved after relog? |
|---|---|---|
| ox_inventory (ESX, Qbox, ox_core, ND_Core) | exports.ox_inventory:AddItem (server) | Yes |
| QBCore with qb-inventory | Player.Functions.AddItem (server) | Yes |
| ESX Legacy default loadout | xPlayer.addWeapon (server) | Yes |
| Standalone / vMenu / PvP | GiveWeaponToPed (client or server) | No — the game forgets on disconnect |
#ox_inventory
In ox_inventory a weapon is an item whose name is the weapon name. Add it on the server; the inventory handles equipping, ammo, durability and saving.
-- Give a pistol with a serial and 12 rounds loaded
local ok, response = exports.ox_inventory:AddItem(source, 'WEAPON_PISTOL', 1, {
ammo = 12,
serial = 'POL' .. math.random(100000, 999999),
})
if not ok then
print(('Could not give weapon to %s: %s'):format(source, response))
end
-- Give spare ammunition as its own item
exports.ox_inventory:AddItem(source, 'ammo-9', 48)AddItem returns false and a reason when it fails — typically the player is too heavy or out of slots — so check it. The metadata fields ox_inventory understands for weapons, such as serial, ammo, durability and components, are covered in ox_inventory metadata, and full weapon setup in the ox_inventory weapon guide.
#QBCore (qb-inventory)
local QBCore = exports['qb-core']:GetCoreObject()
local Player = QBCore.Functions.GetPlayer(source)
if Player then
Player.Functions.AddItem('weapon_pistol', 1, false, { serie = 'POL123456', quality = 100 })
TriggerClientEvent('qb-inventory:client:ItemBox', source, QBCore.Shared.Items['weapon_pistol'], 'add')
endQBCore item names are lowercase (weapon_pistol) and must exist in qb-core/shared/items.lua and shared/weapons.lua. The metadata field names differ between qb-inventory versions — older versions use serie for the serial. See QBCore shared items and QBCore shared weapons.
#ESX Legacy
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.addWeapon('WEAPON_PISTOL', 12) -- name, ammo
end
-- Check before giving
if not xPlayer.hasWeapon('WEAPON_PISTOL') then
xPlayer.addWeapon('WEAPON_PISTOL', 12)
endThis applies to ESX’s built-in loadout. Many ESX servers now run ox_inventory instead, in which case use the ox_inventory method above. ESX items and loadout explains the difference.
#The raw native (standalone servers)
GiveWeaponToPed gives a weapon directly to a ped. Its parameters are the ped, the weapon hash, the ammo count, whether the weapon is hidden, and whether to force it into the ped’s hand.
local ped = PlayerPedId()
GiveWeaponToPed(ped, `WEAPON_CARBINERIFLE`, 250, false, true)
-- Useful companions
SetPedAmmo(ped, `WEAPON_CARBINERIFLE`, 250)
SetCurrentPedWeapon(ped, `WEAPON_CARBINERIFLE`, true)
RemoveWeaponFromPed(ped, `WEAPON_CARBINERIFLE`)
RemoveAllPedWeapons(ped, true)With OneSync you can call it on the server against a player’s ped: GiveWeaponToPed(GetPlayerPed(source), joaat('WEAPON_PISTOL'), 50, false, true). Server-side is preferable because a client cannot fake it.
#A safe admin give-weapon command
Admin commands are the most common way cheaters get weapons — through an unprotected event. Keep the whole command on the server and protect it with an ACE.
RegisterCommand('giveweapon', function(source, args)
local target = tonumber(args[1])
local weapon = args[2] and args[2]:upper()
if not target or not weapon or not GetPlayerName(target) then
return print('usage: /giveweapon <id> <WEAPON_NAME>')
end
local ok, why = exports.ox_inventory:AddItem(target, weapon, 1)
print(('%s gave %s to %s: %s'):format(source, weapon, target, ok and 'ok' or why))
end, true) -- true = restricted: needs the ACE 'command.giveweapon'add_ace group.admin command.giveweapon allowThe full server.cfg reference, including where add_ace lines go, is on the minimap studio: the FiveM server.cfg guide.
#Why client-side giving gets flagged
Anticheats — and ox_inventory itself — compare the weapons a ped holds with what the server says the player owns. A weapon that appears on the client without a matching server record is the signature of a mod menu. Scripts that give weapons from the client produce exactly that signature for honest players. Server-side weapon validation shows how to check it yourself.
Questions
How do I give a weapon in FiveM?
exports.ox_inventory:AddItem(source, 'WEAPON_PISTOL', 1) on the server. On a standalone server, use GiveWeaponToPed(ped, hash, ammo, false, true).Why does the weapon disappear when the player relogs?
Why does ox_inventory remove the weapon I gave with GiveWeaponToPed?
AddItem export instead.Is it safe to give weapons from a client event?
How do I give ammo with the weapon?
{ ammo = 12 } as metadata and add ammo items like ammo-9; with the native, pass the ammo count as the third argument or use SetPedAmmo.Ready to pick a map?
Twelve themes on three base map styles, $8 each, instant download.
Relevant to what you just read
The tool for this
Twenty theme pairs for ox_lib and ox_inventory From $15, built in the browser, exported as a drop-in resource.
Look it up while you work
The reference tables this guide leans on, free and without an account.
- All 860 ped model namesEvery model GetHashKey resolves, with its hash and how many clothing components and props it carries.