So i want to respawn the player without resetting his health variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 3.141592653589
enter code here	if hit == true:
	lives -= 1
	dead = true
	$CollisionShape2D.disabled = true
if lives == 0:
	lives = 3

if dead == true:
	$Particles2D.emitting = true
	Jump_force = Vector2.ZERO
	Max_speed = 0
	direction = Vector2.ZERO
	$AnimationTree.set("parameters/State_mach/current", 2)
	$CollisionShape2D.rotation_degrees = 90
	$Deadcollisionshape.disabled = false
	$CollisionShape2D.disabled = true
	hit = false
	var prev_lives = lives
	yield(get_tree().create_timer(3.0), "timeout")
	dead = false
	$CollisionShape2D.disabled = false
	$Deadcollisionshape.disabled = true
	$Particles2D.emitting = false

func _on_Area2D_body_entered(body):
if “Spikes” in
hit = true

:bust_in_silhouette: Reply From: Zylann

If your plan is to reload the entire scene just to restart the game BUT without resetting player health… then I guess you need to make that health persist outside of the current scene.

One way is to save to a file, but really there is a simpler way: you can use an autoload.
Autoload nodes remain accessible even after you reload the scene, they stay there until the game closes.
So you can store health there, reload, and set back the health after the reload.

There are more sophisticated ways (like taking out the player node, reload, and re-add it / or not using reload_current_scene and instead introduce the concept of “restart” to all game objects) but autoload is simple to begin with.