Functions not updating before other functions are running! help!

version 3.5.3
MacOS

I have a pixel art game where the player has to go and talk to a wise cube. when the player gets close to the cube and presses enter they enter a chat (which is a new scene)

i’m a beginner so the answer to the problem is probably really straightforward but every time the player enters the group wisecube it sets canchangescene to true, but I want it so that when the player isnt colliding with the wisecube group the canchangescene variable is set back to false. everything i’ve tried hasn’t worked so I need help!

var canchangescene = true

func _on_PlayerCollision_area_entered(area):
	if area.is_in_group("wisecube"):
		canchangescene = true

if canchangescene==true and Input.is_action_pressed("ui_accept"):
	get_tree().change_scene("res://scenes/WiseCubeTalk.tscn")
	print("Changing scene...")

Did you try using the “area_exited” signal?

As shatterd said you can use ‘area_exited’. Also…

I don’t know what your other scene code is like but what I would do is …

if canchangescene==true and Input.is_action_pressed("ui_accept"):
	get_tree().change_scene("res://scenes/WiseCubeTalk.tscn")
	print("Changing scene...")
	canchangescene = false

If changescene is no longer necessary then you can just change it back to false once you interact with the wisecube.

I’m not sure that would work if the script is in the current scene, since once the scene changes the script won’t be there to have canchangescene set to false.

ive got the scene transitions working, but one of the problems im having is that when you enter the “wisecube” collider and press space/enter afterwards it doesn’t change the scene, but off you hold space while entering the collider then it does change scene.

I think that might be because you only check if the player is holding down the key when they enter the area. You should use the _input or _unhandled_input function to detect inputs.

that fixed it! (using the area exited signal) thanks, sorry for the inconvenience