[Problem] Not updating user balance in menu

Hello. I’m having a problem with my ESX banking script and I have no idea how to solve that. It won’t update the user balance when he withdraw or deposit money in his account. Here’s the code if anybody can help me…

ESX = nil
local balances = {}
local user = nil

AddEventHandler('es:playerLoaded', function(source)
    local _source = source
    
    TriggerEvent('es:getPlayerFromId', _source, function(user)
    balances[_source] = user.getBank()
    TriggerClientEvent('banking:updateBalance', _source, user.getBank())
  end)
end)


AddEventHandler('playerDropped', function()
    local _source = source
  balances[_source] = nil
  _source = nil
  user = nil
  souce = nil
end)


TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)


function bankBalance(player)
  return exports.essentialmode:getPlayerFromId(player).getBank()
end


-- Bank Deposit
RegisterServerEvent('bank:deposit')
AddEventHandler('bank:deposit', function(amount)
	local _source = source
	
	local xPlayer = ESX.GetPlayerFromId(_source)
	if amount == nil or amount <= 0 or amount > xPlayer.getMoney() then
		TriggerClientEvent('chatMessage', _source, "Invalid Amount")
	else
		xPlayer.removeMoney(amount)
		xPlayer.addAccountMoney('bank', tonumber(amount))
	end
end)

-- Bank Withdraw
RegisterServerEvent('bank:withdraw')
AddEventHandler('bank:withdraw', function(amount)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	local base = 0
	amount = tonumber(amount)
	base = xPlayer.getAccount('bank').money
	if amount == nil or amount <= 0 or amount > base then
		TriggerClientEvent('chatMessage', _source, "Invalid Amount")
	else
		xPlayer.removeAccountMoney('bank', amount)
		xPlayer.addMoney(amount)
	end
end)

-- Bank Transfer
RegisterServerEvent('bank:transfer')
AddEventHandler('bank:transfer', function(to, amountt)
	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
	local zPlayer = ESX.GetPlayerFromId(to)
	local balance = 0
	balance = xPlayer.getAccount('bank').money
	zbalance = zPlayer.getAccount('bank').money
	
	if tonumber(_source) == tonumber(to) then
		TriggerClientEvent('chatMessage', _source, "You cannot transfer to your self")
	else
		if balance <= 0 or balance < tonumber(amountt) then
			TriggerClientEvent('chatMessage', _source, "You don't have enough money in the bank.")
		else
			xPlayer.removeAccountMoney('bank', amountt)
			zPlayer.addAccountMoney('bank', amountt)
		end
		
	end
end)

-- Send NUI message to update bank balance
RegisterNetEvent('banking:updateBalance')
AddEventHandler('banking:updateBalance', function(balance)
  local id = PlayerId()
  local playerName = GetPlayerName(id)
	SendNUIMessage({
		updateBalance = true,
		balance = balance,
    player = playerName
	})
end)

Help… please?:frowning:

Do you errrhh… Have a db setup?.

Yes, I have. But it won’t update the user balance in the banking ui menu and have no idea why not.

same !!!