Multiple Levels Help

I thought it would just be easier to duplicate scenes when creating multiple levels, however all my scripts are based on level 1, so my buttons when pressing play again when the level has ended - based on completing it or dying, on my other levels, will automatically go to level 1, because of the duplicated script.

Is there a way I can use a global variable to check what scene it was just on, and then make the button go to that most recent scene? Thank you.

extends Node2D

func _on_button_pressed() → void:
get_tree().change_scene_to_file(“res://scenes/…. # i want this to go the scene it was currently on

func _on_button_2_pressed() → void:
get_tree().change_scene_to_file(“res://scenes/Levels.tscn”)

You can use SceneTree::reload_current_scene()

1 Like

I tried it, and now I can’t click the button for some reason?

Which button would that be and what do you mean by “can’t click”?

func _on_button_pressed() → void:
get_tree().reload_current_scene() - this one

That’s not a button, it’s a signal handling function.

1 Like

Maybe post your scene tree and if your control node not override capture mouse

1 Like

oh so what should i do..

Present your problem better by providing more information and context.