MaDHouSe79 / mh-cashasitem

The best cash/blackmoney/crypto item script for your qbcore server created by MaDHouSe79.
GNU General Public License v3.0
41 stars 9 forks source link

Problems with money drops #27

Closed web-caos closed 7 months ago

web-caos commented 7 months ago

Everytime i try to drop money and then get them back i get this error: SCRIPT ERROR: @qb-inventory/server/main.lua:989: attempt to index a nil value (field '?') And money still dropped Any idea?

xamixami471 commented 7 months ago

set in your qb-core/config.lua on line 9 and 10 like this : QBConfig.Money = {} QBConfig.Money.MoneyTypes = { cash = 500, bank = 5000, crypto = 0, blackmoney = 0 } QBConfig.Money.DontAllowMinus = { 'cash', 'crypto', 'blackmoney' }

MaDHouSe79 commented 7 months ago

do you use a default qb-core? with the default scripts?

LaceUpBrah commented 7 months ago

do you use a default qb-core? with the default scripts?

Hi. I'm having the exact same issue but for me it happens every time I open the inventory.

image

It says that this right here is the issue but I've followed your tutorial, everything works fine expect this console error.

image

MaDHouSe79 commented 7 months ago

do you use a default qb-core? with the default scripts?

Hi. I'm having the exact same issue but for me it happens every time I open the inventory.

image

It says that this right here is the issue but I've followed your tutorial, everything works fine expect this console error.

image

Do you have the item in your inventory? cause it looks like the cash is nil and why this is not a number.

Add on line 40 above the if count >=1 and cash >=1 then print(itemCount, cash)

print(itemCount, cash) -- <-- Add Here
if itemCount >= 1 and cash >= 1 then
    ItemBox(lastItem, Player, itemCount, "remove")
    AddItem(moneyType, Player, cash, lastSlot)
elseif itemCount <= 0 and cash >= 1 then
    AddItem(moneyType, Player, cash, lastSlot)
end

if that gives a nil then try to replace the function with this function, and see if that works for you.

local function UpdateCashItem(src, moneyType)
    local Player = QBCore.Functions.GetPlayer(src)
    if Player then
        local cash = Player.Functions.GetMoney(moneyType)
        local itemCount, lastSlot, lastItem = 0, nil, nil
        for _, item in pairs(Player.PlayerData.items) do
            if item and item.name:lower() == moneyType then
                itemCount = itemCount + item.amount
                lastSlot = item.slot
                lastItem = item.name
                Player.Functions.RemoveItem(item.name, item.amount, item.slot)
            end
        end
        if type(itemCount) == 'number' and type(cash) == 'number' then -- << add
            if itemCount >= 1 and cash >= 1 then
                ItemBox(lastItem, Player, itemCount, "remove")
                AddItem(moneyType, Player, cash, lastSlot)
            elseif itemCount <= 0 and cash >= 1 then
                AddItem(moneyType, Player, cash, lastSlot)
            end
        end -- << add
    end
end
LaceUpBrah commented 7 months ago

if that gives a nil then try to replace the function with this function, and see if that works for you.

local function UpdateCashItem(src, moneyType)
    local Player = QBCore.Functions.GetPlayer(src)
    if Player then
        local cash = Player.Functions.GetMoney(moneyType)
        local itemCount, lastSlot, lastItem = 0, nil, nil
        for _, item in pairs(Player.PlayerData.items) do
            if item and item.name:lower() == moneyType then
                itemCount = itemCount + item.amount
                lastSlot = item.slot
                lastItem = item.name
                Player.Functions.RemoveItem(item.name, item.amount, item.slot)
            end
        end
        if type(itemCount) == 'number' and type(cash) == 'number' then -- << add
            if itemCount >= 1 and cash >= 1 then
                ItemBox(lastItem, Player, itemCount, "remove")
                AddItem(moneyType, Player, cash, lastSlot)
            elseif itemCount <= 0 and cash >= 1 then
                AddItem(moneyType, Player, cash, lastSlot)
            end
        end -- << add
    end
end

My man, you just fixed the issue. No more errors and everything works as it should. You're the best! Thank you.