In-game Currency - how to

Hi, I need to create an in-game currency. Well, actually I already managed to create it but I wonder how can I add new “money” to the old one? I’m using this code to save my data (more specifically the reading and writing files).

Everything is working fine but how can I add new money to the previous ones?
Thank you in advance

I use json instead of txt, the process is almost the same.

You can parse the json file to become a lua table, so you can handle the data as any other lua table. Then, when you want to save the game, you parse the lua table to json and save it.

Do not save your game for every single change since that is a a heavy process. Instead save it on key points.

To decode json use:

local jsonParser = require("json")
savedData = jsonParser.decode(fileContent)

And to encode:

local jsonParser = require("json")

Where savedData is a lua table.