attempt to call a nil value (field 'getMoney')
ESX changed its API: getMoney() no longer exists. Here is the correct method to read the player's money.
The problem
When calling `xPlayer.getMoney()` the console throws "attempt to call a nil value (field 'getMoney')".
The cause
ESX Legacy reorganized the player's accounts. `getMoney()` was removed; money now lives inside the accounts and is read with `getAccount`.
The solution
Replace getMoney with getAccount('money'):
lua
-- ❌ Old (no longer exists)
local money = xPlayer.getMoney()
-- ✅ Correct in ESX Legacy
local money = xPlayer.getAccount('money').money
-- Defensive compatibility in case you mix versions:
local function getPlayerMoney(xPlayer)
if xPlayer.getAccount then
return xPlayer.getAccount('money').money
end
return xPlayer.money or 0
endStep by step
- 1.Replace all calls to `getMoney()` with `getAccount('money').money`.
- 2.For bank use `getAccount('bank')`, for dirty money `getAccount('black_money')`.
- 3.Remember: giving/removing money is ALWAYS validated and executed on the server (server-authoritative).
Related guides
Last updated: 2026-06-15. Crxative-M is not affiliated with Cfx.re or Rockstar Games.
