Map triggered lua counter

Hey, I’m working on a potential gamemode at the moment that will require a way of keeping track of, and utilizing numbers down to single digit integers, which is tedious to set up in hammer for flexible use.
Essentially I need the player to be able to earn money, then have the game check for an amount (or more) and subtract it from their total when they activate an object on the map, performing a function ingame such as spawning a structure or piece of equipment. Here is a crude illustration of one example of it’s implementation.

So specifically speaking, I need a lua counter mechanism that keeps track of player balance, checks for specified balance on input for sufficient funds while firing either an OK or NOT OK output, and has independent inputs which can be fired to add or subtract from the player’s existing balance.

Any help would be appreciated, thank you.

You can use the lua_run entity to set and read a var on the player