- do not use
Tick
+Delay
, especially for this - you’re loading your game 60 times per second, flood the Delay every frame and then save the game every 30s.
- create an event for saving the game
- create an event for loading the game
- use a timer to count the energy when the game runs
- before player quits the game, save the amount of energy they had and a timestamp
- when they load the game, check the amount of energy saved and calculate how much time has passed since last save
- if you want to have a cap on the amount of energy that can be restored, you could clamp it
It could look close to this: