Game Won't Save Properly On Device

I am new to reading and writing files. I don’t know what I’m doing wrong, it will save on the simulator infinitely and will only save once or twice on the device. Is someone willing to help me out with this? I will be extremely grateful!

num2Counter = 0 function onSystem(e) if e.type == "applicationStart" then path = system.pathForFile("file\_save",system.DocumentsDirectory) file = io.open(path,"r") if file then num2Counter = file:read(1) num2Counter = tonumber(num2Counter) print("Load: 1",num2Counter) io.close(file) else path = system.pathForFile("file\_save",system.DocumentsDirectory) file = io.open(path,"w") file:write(num2Counter) print("Save:",num2Counter) io.close(file) end elseif e.type == "applicationExit" then path = system.pathForFile("file\_save",system.DocumentsDirectory) file = io.open(path,"w") file:write(num2Counter) print("Save:",num2Counter) io.close(file) elseif e.type == "applicationSuspend" then physics.pause() elseif e.type == "applicationResume" then physics.start() end end Runtime:addEventListener("system", onSystem)

try changing this

elseif e.type == “applicationExit” then

to this

elseif e.type == “applicationExit” or e.type == “applicationSuspend” then

most times apps just suspend

try changing this

elseif e.type == “applicationExit” then

to this

elseif e.type == “applicationExit” or e.type == “applicationSuspend” then

most times apps just suspend