IDLE GAME: changing the scenes affects the player's status

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

Hello, i started using godot like a week ago and im working on a simple game (obs watching tutorials on yt).

I have a Menu scene (which contains 3 buttons, Start, Option, Exit) and a World scene (which contains the Player/Monsters/Bushes etc). Selecting start will change the scene from Menu to World, if the player dies from the World to Menu. (works fine)

The problem is when i select Start button again, the player is not starting with the full HP like before.

The code is quite big so i’ll use the Pastebin (i hope it’s ok to do that) and some Printscreens to see how i organized the nodes.
Player script: extends KinematicBody2Dexport var MAX_SPEED = 80export var acceleration -
Player scene: PlayerScene - Album on Imgur
SceneTransition script: extends ColorRectexport(String, FILE, ".tscn") var next_scene_pathonread -
PlayerStats script: extends Node2Dexport(int) var max_health = 1 setget set_max_health #de fieca -

:bust_in_silhouette: Reply From: Ahotenus

You have the player stats in a singleton when you reset the scene the singleton is not doing it, so you have the old values of it, this is because the singleton is outside the general tree, you can see it in the remote tab when you click play

What do you think the best solution is for that problem ? Not making the player stats as a singletone ?

ispilantebrusli | 2021-08-12 10:03

Update: I fix it by setting the player health in the ready function and i think it works fine

ispilantebrusli | 2021-08-12 13:13