How to delete a specific node at your mouse position

Hi, I’m building a user placement system which I’m very new to and I’m trying to build a system to delete tiles. Right now when I click anywhere on the screen, the last node that was placed gets deleted but I want to delete a specific node where my mouse position is.

Code

elif(currentBuildMode == buildingModes[2]):
get_global_mouse_position()
for node in get_tree().get_nodes_in_group(“Crops”):
if node.is_in_group(“Crops”):
node.queue_free()
break

The section above is the deletion part of the user placement system.

I’ve tried adding another if statement such as if node.position == get_global_mouse_position()but that just breaks the deletion system and nothing happens. My theory is get_all_nodes_in_group just gets every single node in that group and it doesn’t run since not all nodes are under your mouse position I may be wrong on that.

Below is a screen recording showing what happens

For mouse interaction you’d typically use Area2D nodes along the visual representation. Those nodes can detect that mouse clicks inside their shapes. So each of your sprite should have a corresponding area node.

You can also do it without areas by calculating each sprite’s global bounding rectangle and then checking if the mouse click position is within.