I wrote a library (one of many out there, I’m sure) to help with filing operations. With this, you can keep a table of tables for scores and write it to the documents (or any other) folder in one line:
https://gist.github.com/HoraceBury/d8d2fa3382f82a7c7faa
For example, this code would load a scores file, if it’s there, add or update the high score for level 10 and save it again:
-- load the io library local iolib = require("iolib") -- initialise the scores table local scores = {} -- load the scores file if it exists in the documents folder if (iolib.docExists( "scores.json" )) then scores = iolib.wrDocs( "scores.json" ) end -- create the level 10 table inside the scores table, if necessary scores[10] = scores[10] or { highscore=0 } -- update the level 10 high score value scores[10].highscore = 132 -- save the scores table to the documents folder iolib.wrDocs( "scores.json", scores )