Increase a variable while game is offline

Hi! I have an android game that I’m about to make, and I’d like to ask how to create a certain feature found in idle games like Tap Titans and AdVenture Capitalist wherein you can gain currency even after you quit the game.

I know it’s impossible to actually create a script that runs after the game just so it can track the currency variable, but I just want to be given insight on what methods or ways I could implement this from a scripting perspective?

When your game has only local logic, you can simply store the Date and time when you exit the game. Then if you are starting the game again, compare the date and time of your last exit with the current date and time. Depending on how any hours etc. were between your exit and the start, add the amount to your player’s currency. Of course, You have to save the latest currency value of your player too.

When it is an online multiplayer game, that requires a server and you are responsible for the server code, then handle this with the server time. Since it is less likely that someone exploits this feature (on the phone, you could set the date a few years ahead and earn a huge amount of ingame money upon restarting the game).
Alternatively, you can have your game run locally, but for the time checks communicate with an independent server that will provide consistent time information. This way, the feature is not easy exploitable by the user.