Something like this?
var has_button_been_pressed = false
func _pressed():
var button = get_tree().get_root().get_node("Node/Button")
var panel = button.get_node("Panel")
if (panel.visible == true and has_button_been_pressed == true):
button.visible = false
else:
panel.visible = true
has_button_been_pressed = true
I'm not sure if it is really the best way of doing this, nor if it is better, but off the top of my head that is how I would handle it. Depending on how your project and UI is setup, you might be able to remove has_button_been_pressed
and just use panel.visible
for toggling the button's visibility.
Hopefully this helps a bit!