# Giving weapons to players in FiveM, the right way for your server

> Give weapons in FiveM with GiveWeaponToPed or properly through ox_inventory, QBCore and ESX so they save — working code, ammo and anticheat notes.

Source: https://fam-tools.com/guides/fivem-give-weapon-to-player · FAM Tools · published 2026-09-11 · updated 2026-09-11 · about 12 min

**Short answer.** 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.

## Key points

- With an inventory, the **inventory is the source of truth** — add the item on the server.
- `GiveWeaponToPed(ped, hash, ammo, isHidden, bForceInHand)` is the raw native, for standalone servers.
- Never give weapons from a client event the client can trigger — that is how cheaters give themselves guns.
- Admin commands belong on the server behind an ACE permission.

“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 |

> **Calling the native on an inventory server** — If ox_inventory manages weapons and a script calls `GiveWeaponToPed` directly, the inventory does not know about the gun. Depending on configuration it removes it again or flags the player. Always go through the inventory’s API.

## 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.

*server.lua*

```lua
-- 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](https://fam-tools.com/guides/ox-inventory-metadata), and full weapon setup in [the ox_inventory weapon guide](https://fam-tools.com/guides/ox-inventory-weapon-setup).

## QBCore (qb-inventory)

*server.lua*

```lua
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')
end
```

QBCore 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](https://fam-tools.com/guides/qbcore-shared-items) and [QBCore shared weapons](https://fam-tools.com/guides/qbcore-shared-weapons).

## ESX Legacy

*server.lua*

```lua
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)
end
```

This 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](https://fam-tools.com/guides/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.

*client.lua*

```lua
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.

*server.lua — ox_inventory example*

```lua
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'
```

*server.cfg*

```cfg
add_ace group.admin command.giveweapon allow
```

The full server.cfg reference, including where `add_ace` lines go, is on the minimap studio: [the FiveM server.cfg guide](https://fam-tools.com/guides/fivem-server-cfg).

## 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](https://fam-tools.com/guides/fivem-weapon-anticheat-validation) shows how to check it yourself.

## Questions

### How do I give a weapon in FiveM?

On a server with ox_inventory, call `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?

It was given with the native only, so no inventory or database recorded it. Give it through your inventory or framework so it is saved.

### Why does ox_inventory remove the weapon I gave with GiveWeaponToPed?

ox_inventory owns weapons on the server. A weapon it did not hand out is treated as illegitimate. Use its `AddItem` export instead.

### Is it safe to give weapons from a client event?

No. Any client event can be triggered by a cheater. Keep giving on the server and validate who is asking.

### How do I give ammo with the weapon?

In ox_inventory pass `{ 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`.

## Related

- https://fam-tools.com/guides/gta-5-weapon-names-hashes-list
- https://fam-tools.com/guides/ox-inventory-weapon-setup
- https://fam-tools.com/guides/fivem-weapon-anticheat-validation
- https://fam-tools.com/guides/fivem-ammo-types-and-items
- https://fam-tools.com/guides/fivem-remove-weapon-from-player
