Closed web-caos closed 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' }
do you use a default qb-core? with the default scripts?
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.
It says that this right here is the issue but I've followed your tutorial, everything works fine expect this console error.
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.
It says that this right here is the issue but I've followed your tutorial, everything works fine expect this console error.
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
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.
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?