Hey all, i’m having trouble with my script. So far, everything works except when it gets to the ESX server functions. I know that it is sending the proper amount of money that the player wants to deposit to the server, but for some reason it doesn’t do anything past that (i’m guessing it fails in the if statement inside of the server script)
From the ESX GitHub, here are the functions that i’m using:
xPlayer.setAccountMoney(a, m)
xPlayer.getMoney()
xPlayer.removeMoney()
Here’s my script:
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
RegisterCommand("deposit", function(source, args, rawCommand)
if isPlayerNearBank() or isPlayerNearAtm() then
local requestedDeposit = args[1]
if not requestedDeposit then -- if requestedDeposit is nil
TriggerEvent("chatMessage", "Usage", { 0, 128, 0 }, "/deposit [amount]")
elseif requestedDeposit ~= nil then
TriggerServerEvent("ezbanks:depositEvent", requestedDeposit)
end
else
TriggerEvent("chatMessage", "", { 0, 0, 0 }, "You not near a bank or ATM.")
end
end)
ESX = nil
TriggerEvent("esx:getSharedObject", function(obj) ESX = obj end)
RegisterServerEvent("ezbanks:depositEvent")
AddEventHandler("ezbanks:depositEvent", function(amount)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
TriggerClientEvent("chatMessage", _source, "You entered:" .. amount) -- works up to here
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)
As far as i’m concerned, literally everything in this script is correct. I can’t understand why it isn’t working. No errors in F8 console in game either, just simply doesn’t remove money or add it to the bank account. Any help would be greatly appreciated. Thanks!