Dragging an item from inventory to world

v4.2.1.stable.official [b09f793f5]

I’m trying to drop an item from my inventory to the world. What I’ve written is successful, but rarely instead of dropping the item it will store the item and save it for the next drop, where it will drop both the stored item and the dropped item.
So what I’m asking is, what’s wrong with my code?

extends TextureRect
func _get_drag_data(_at_position):
	#some code

func _can_drop_data(_at_position, _data):
	#some code

func _drop_data(_at_position, data):
	#some code

func _input(_event):
	if Input.is_action_just_released("use_tool"):
		if is_drag_successful() == false:
			if mouse == false:
				if dropped_item:
					print("what")
					Inventory.pass_the_item.emit(dropped_item, dropped_quantity)
					dropped_item = null
					dropped_quantity = null

func _on_slot_1_mouse_entered():
	mouse = true

func _on_slot_1_mouse_exited():
	mouse = false

----------------------------------------------

extends GridContainer

func _ready():
	Inventory.pass_the_item.connect(pass_the_dropped_item)

func pass_the_dropped_item(drop_item, slot_quantity):
	print("Button release")
	Inventory.outOfBounds.emit(drop_item, slot_quantity)

----------------------------------------------

extends Node2D

@onready var item_scene = preload("res://World/Items/Item.tscn")

func _ready():
	Inventory.outOfBounds.connect(add_item_to_world)

func add_item_to_world(item, quantity):
	var item_instance := item_scene.instantiate()
	item_instance.item_type = item
	item_instance.item_quantity = quantity
	item_instance.position = get_global_mouse_position()
	add_child(item_instance)

I fixed this with the following changed code:

func _input(_event):
	if dropped_index == slot_index:
		if Input.is_action_just_released("use_tool"):
			if mouse == false:
				if dropped_item:
					Inventory.pass_the_item.emit(dropped_item, dropped_quantity)
					dropped_item = null
					dropped_quantity = null
					dropped_index = null

I also changed the mouse check from one of the slots to the container that holds all of the slots.

I have to scrap all of this because I still have a problem where I can click specific areas on the screen and the item will just disappear.