> For the complete documentation index, see [llms.txt](https://aklgaming.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aklgaming.gitbook.io/documentation/code-snippets/item-probability.md).

# Item Probability

How to make a probability item system

{% tabs %}
{% tab title="client" %}

```lua
RegisterNetEvent('gusti-lootcrate:openCrate')
AddEventHandler('gusti-lootcrate:openCrate', function()
    ESX.TriggerServerCallback('gusti-lootcrate:openCrate', function(success)
        if success then
            ESX.ShowNotification('You received an item!')
        else
            ESX.ShowNotification('You cannot carry more items.')
        end
    end)
end)
```

{% endtab %}

{% tab title="server" %}

```lua
ESX.RegisterServerCallback('gusti-lootcrate:openCrate', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)
    local item

    local chance = math.random(100)

    if chance <= 50 then
        item = 'legendary_item'
    elseif chance <= 80 then
        item = 'special_item'
    else
        item = 'epic_item'
    end

    if xPlayer.canCarryItem(item, 1) then
        xPlayer.addInventoryItem(item, 1)
        cb(true)
    else
        cb(false)
    end
end)
```

{% endtab %}
{% endtabs %}
