'How can I update the script from limit to weight? Lua

I use this ambulance job that is made in Lua. Unfortunately, being an old script, it's not updated, so it was still set to use "limit" which I changed to "weight" since my gamemode is based on weight as well as the database. But sadly it doesn't work, I get this error.

    RegisterServerEvent('esx_ambulancejob:giveItem')
AddEventHandler('esx_ambulancejob:giveItem', function(itemName)
    local xPlayer = ESX.GetPlayerFromId(source)

    if xPlayer.job.name ~= 'ambulance' then
        print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
        return
    elseif (itemName ~= 'medikit' and itemName ~= 'bandage') then
        print(('esx_ambulancejob: %s attempted to spawn in an item!'):format(xPlayer.identifier))
        return
    end

    local xItem = xPlayer.getInventoryItem(itemName)
    local count = 1

    if xItem.weight ~= -1 then (it was xItem.limit before)
        count = xItem.weight - xItem.count
    end

    if xItem.count < xItem.weight then
        xPlayer.addInventoryItem(itemName, count)
    else
        TriggerClientEvent('esx:showNotification', source, _U('max_item'))
    end
end)

The error screen when I try to take the item from the pharmacy:

Console Error Image



Solution 1:[1]

I don't know which line is 263, but error says object_name.weight is nil.

Watching code, xItem doen't have field weight (xItem.weight = nil).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reinisdm