Having issues with essentialmode money system

I’m having difficulties trying to access the money stored in EssentialMode’s database. I’m using EssentialMode Robbery System as a source of money (I had to fix the resource myself since it wasn’t working originally) and after the money gets added to the database, and I exit the server and log back in, I can’t see the money I have until I break into another store (until new money gets added)

I’ve tried this (slightly modified) method of updating the money when a player logs in from here:

AddEventHandler('es:playerLoaded', function(source)
-- Get the current amount for the player
 TriggerEvent('es:getPlayerFromId', source, function(user)
 -- Activate the money for the current player
   user:setMoney(user.money)

 -- Send the player some information regarding the money
 TriggerClientEvent('chatMessage', source, "SYSTEM", {187, 235, 42}, "Your money amount is: $" .. tostring(user.money))
  end)
end)

and when I log in I get this error from the server console:

ES_ERROR: There seems to be an issue while setting money, something else then a number was entered.

I also get the message in the FiveM chat like

SYSTEM: Your money amount is: $nil

When I rob stores, the money gets added to what i’ve had before, but when I access CouchDB from my browser, there’s only one entry in essentialmode database with money: 0, bank: 0

Any ideas ?

Same problem here. Did you get something new about this?

Due to the Class change with Essentialmode update, the getters were changed. Update your following code to reflect this:

AddEventHandler('es:playerLoaded', function(source)
-- Get the current amount for the player
 TriggerEvent('es:getPlayerFromId', source, function(user)
 -- Activate the money for the current player
    --user:setMoney(user.money)
    user.addMoney(0)

 -- Send the player some information regarding the money
 TriggerClientEvent('chatMessage', source, "SYSTEM", {187, 235, 42}, "Your money amount is: $" .. tonumber(user.getMoney()))
  end)
end)

The part where it says “Activate the money for the current player” isn’t needed. You are passing a null integer to set the money to a value and creates an error. Use user.addMoney instead, using 0 as a valid integer so it doesn’t change the money itself, yet still activates it :).

To get your money and bank info working, get es_ui. Do not download the release, download from the master branch or use git. Actually after you get the update es_ui code you will no longer have to fake add money to trigger it. I also will refrain from using esx.

You could also make it into a command to test and debug with via:

AddEventHandler('chatMessage', function(source, name, msg)
  sm = stringsplit(msg, " ");
  if sm[1] == "/money" then
    CancelEvent()
    TriggerEvent('es:getPlayerFromId', source, function(user)
    user.addMoney(0)
    TriggerClientEvent('chatMessage', source, "SYSTEM", {187, 235, 42}, "\nMoney: $" .. tonumber(user.getMoney()) .. " \nBank: $" .. tonumber(user.getBank()))
    end)
  end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

put it in a server-side script and type /money