How can I make a variable that persists between scene resets

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By The Benjameister

To keep it simple, my game is a platformer. I want to be able to keep track of how many times the player has died, as well as a timer from when they started so they can try and beat the game faster on the next playthrough.

When the player dies, I call get_tree().reload_current_scene() in order to reset the scene. I haven’t found a way to have a variable that ticks up every single time the player dies (scene resets) and a way to keep the timer from resetting back to what it was when the scene started.

How can I do this?

:bust_in_silhouette: Reply From: kidscancode

You can use an autoload for this:

Autoloads are nodes that are automatically loaded by the SceneTree, separately from the current scene. They therefore remain when reloading the scene.