Looking at the code, I do not see anything that would be causing the inventory to close on every click. I have two theories on what could potentially be causing the problem.
One thing that could be causing the issue is another node, or nodes, are being placed on top of the Area2D node. Then when the inventory is open, these nodes get in the way of the Area2D and cause the mouse_exit signal to be sent, making detect false. If this is what is causing the issue, then I'm not really sure what the best way to go about fixing it would be. I did a Google search, and found this QA answer, but I'm not sure how applicable or helpful it will be for this problem.
Another thing that could be causing the issue is that Input.is_mouse_button_pressed is being called multiple times, and so the inventory is rapidly switching from open to close. In theory, all you would need to do something like the code below so only the initial click is used:
var left_mouse_down = false
func _process(delta):
if Input.is_mouse_button_pressed(BUTTON_LEFT):
if left_mouse_down == false:
left_mouse_down = true
if detect == true:
get_parent().get_node("Inventory").show()
print("it's open")
else:
get_parent().get_node("Inventory").hide()
print("it's closed")
else:
left_mouse_down = false;
Personally, I doubt this is the issue, but looking at the code I do not see anything else. Honestly, the code looks fine, which makes me think the issues is more in line with the first theory, that something is blocking the Area2D nodes.
I wish I could give a better answer, but honestly I'm not sure what is causing the issue.
Hopefully this helps! :smile: