I use resource script (a class that extends Resource, called also scriptable object). I save "user://save.tres" file, the save.tres is an istance of a script (save_data.gd that extends Resource) with the variable that I want to save. I uploaded the source code, it's not very clear but you can find the save and load functions in the singleton.gd script.