I can't call function "queue_free" on base "nil" even though said base has a value?

im trying to make a simple-looking inventory system that comprises of only an item and it’s buttons, similar to that of deltarune. the _add_item function works as intended, but when i connect the button to the _use_item function (all it does is delete the button, for now) I get a “cannot call queue_free on base ‘nil’”, even though the base has a value. how can i fix this?

for context, the inventory system im working on is a dictionary that comprises of an item (the key) and the button (the key’s value).

sorry if this seems like a dumb question because it’s 1am here and i can’t figure this out.

var inventory: Dictionary[items, BaseButton]

func _add_item(item: items) -> void:
	var item_button = Button.new()
	item_button.text = item.name
	item_button.connect(item_button.pressed, _use_item(item))
	inventory[item] = item_button;
	inventory_handler.add_child(item_button)

func _use_item(item: items):
	var item_button = inventory.find_key(item);
	item_button.queue_free()

Dictionary.find_key() is used to get the key of a specific value. You already have the key and just want to access its value:

	var item_button = inventory[item]

Also, you should consider erasing the dictionary entry after freeing a button.