[SOLVED] Implementing Server Side Check For Item

I’m currently using the awesome Blackjack made by Robbster

Since I use the basic ESX, I’m trying to implement the actual use of chips. The problem however is, even if you don’t have the correct amount of chips for your bet, it’ll still get through, and just puts your amount of chips in the minus, but continues to allow you to bet even with -1000 chips which is extremely abusable if someone wins and gets a return of double their bet.

the code I’m flying with right now is

function tryTakeChips(source, amount)
    local amount = amount
	local _source = source
        local xPlayer = ESX.GetPlayerFromId(_source)

    if xPlayer.getInventoryItem('casinochips', amount) then
        xPlayer.removeInventoryItem('casinochips', amount) 
       return true
    else
       return false
            end    
      end
end

The event at line 73 that calls this function is also server side found at line 85

RegisterNetEvent("Blackjack:setBlackjackBet")
AddEventHandler("Blackjack:setBlackjackBet",function(gameId,betAmount,chairId)
    local source = source

    if gameId ~= nil and betAmount ~= nil and chairId ~= nil then 
        if blackjackGameData[gameId] == nil then
            blackjackGameData[gameId] = {}
        end
        if not blackjackGameInProgress[gameId] then
            if tonumber(betAmount) then
                betAmount = tonumber(betAmount)
                if betAmount > 0 then
                    if tryTakeChips(source,betAmount) then
                        --print("Taken",betAmount,"chips from id",source)
                        if blackjackGameData[gameId][source] == nil then
                            blackjackGameData[gameId][source] = {}
                        end
                        blackjackGameData[gameId][source][1] = betAmount
                        --print("GameId: " .. tostring(gameId) .. " source: " .. tostring(source) .. " has placed a bet of " .. tostring(betAmount))
                        TriggerClientEvent("Blackjack:successBlackjackBet",source)
                        TriggerClientEvent("Blackjack:syncChipsPropBlackjack",-1,betAmount,chairId)
                        TriggerClientEvent("blackjack:notify",source,"~g~Bet placed: " .. tostring(betAmount) .. " chips.")
                    else 
                        TriggerClientEvent("blackjack:notify",source,"~r~Not enough chips!")
                    end
                end
            end
        end
    else
        TriggerClientEvent("blackjack:notify",source,"~r~Error betting!")
    end
end)

Somehow I just can’t get it to refuse the bet if you don’t have the chips for it, the bet goes through regardless. I’m pretty novice at coding so any help is appreciated getting this to work.

its

if xPlayer.getInventoryItem('casinochips').count >= amount then
        xPlayer.removeInventoryItem('casinochips', amount) 
       return true
    else
       return false
    end    
end

ABSOLUTE LIFE SAVER. See I was running with something similar:

if xPlayer.getInventoryItem('casinochips') >= amount then
        xPlayer.removeInventoryItem('casinochips', amount) 
       return true
    else
       return false
    end    
end

But because I forgot .count behind the (casinochips) it would return SCRIPT ERROR: Attempt to compare number with table. I’m such an idiot. Thanks mate <3