Inputended does not fire whenever the frame is being dragged

basically im making an inventory system where you can drag tools like the normal roblox tool in the backpack but the bug is that whenever i start dragging use an inputended connection to stop it but the thing is whenever i start dragging it does not fire

heres the module

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local HttpService = game:GetService("HttpService")
local RunService = game:GetService("RunService")
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")

local Packages = ReplicatedStorage.Packages
local Modules = ReplicatedStorage.Modules

local Shared = Modules.Shared

local Root = script:FindFirstAncestor("InventoryController")

local ToolConfigurer = require(Root.ToolConfigurer)

local Packets = require(Shared.Packets)

local Scheduler = require(Packages.Scheduler)
local TableUtil = require(Packages.TableUtil)
local Observers = require(Packages.Observers)
local Throttle = require(Packages.throttle)
local Promise = require(Packages.Promise)
local Signal = require(Packages.Signal)
local Trove = require(Packages.Trove)
local t = require(Packages.t)

local ModuleLoader = require(Packages.ModuleLoader)

local Player = Players.LocalPlayer

local Mouse = Player:GetMouse()

local PlayerGui = Player.PlayerGui

local MainGui = PlayerGui:WaitForChild("Inventory")
local Canvas = MainGui.Canvas

local BackpackFrame = Canvas.Backpack
local HotbarFrame = Canvas.Hotbar

local HotbarDrag = Canvas.HotbarDrag

local BackpackHolder = BackpackFrame.Holder
local BackpackTemplate = BackpackHolder.Template

local HotbarSlotDragSize = UDim2.new(0.134, 0, 1.336, 0)

export type Location = "Hotbar" | "Backpack" | "none"
export type State = "Drag" | "Idle"

local Dragging = {}

function Dragging.IsDragging()
	return #Dragging ~= 0
end

function Dragging.Add(Identifier)
	table.insert(Dragging, Identifier)
end

function Dragging.Remove(Identifier)
	for Index, ID in ipairs(Dragging) do
		if ID == Identifier then
			Dragging[Index] = nil
		end
	end
end

local ToolUIManager = {}
ToolUIManager.__index = ToolUIManager

local InventoryController : ModuleLoader.ControllerOrService

task.spawn(function()
	ModuleLoader.OnStart():await()

	print("Loaded")

	InventoryController = ModuleLoader.GetController("InventoryController", true)
	print(InventoryController)
end)

export type UIManager = typeof(ToolUIManager) & {
	Tool: Tool,
	ToolConfigure: ToolConfigurer.ToolConfigure,
	Location: Location,
	State: State,
	UIFrame: Frame,
	StateChanged: Signal.Signal,
	LocationChanged: Signal.Signal,
	FrameTrove: Trove,
	StateConnections: Trove,
	Identifier: string
}

function ToolUIManager.new(Tool, ToolConfigure): UIManager
	ModuleLoader.OnStart():await()

	local self = {
		Tool = Tool,
		ToolConfigure = ToolConfigure,
		Location = "none",
		State = "Idle",
		UIFrame = nil,
		StateChanged = Signal.new(),
		LocationChanged = Signal.new(),
		FrameTrove = Trove.new(),
		StateConnections = Trove.new(),
		Identifier = HttpService:GenerateGUID(false)
	} :: UIManager

	self = setmetatable(self, ToolUIManager)
	return self
end

function ToolUIManager.Init(self: UIManager)
	local LocationChanged = self.LocationChanged
	local StateChanged = self.StateChanged
	local ToolConfigure = self.ToolConfigure

	local Equipped = ToolConfigure.Equipped

	Equipped:Connect(function(State)
		local Location = self.Location
		local UIFrame = self.UIFrame

		print(UIFrame, Location)

		if Location == "Hotbar" and UIFrame then
			local Selected = UIFrame.Selected

			Selected.Visible = State
		elseif Location == "Backpack" and UIFrame then
			local Selected = UIFrame.Selected

			Selected.Visible = State
		end
	end)

	StateChanged:Connect(function(OldState: State, NewState: State)
		local FrameTrove = self.FrameTrove
		local StateConnections = self.StateConnections

		StateConnections:Clean()
		FrameTrove:Clean()
		self.StateConnections = Trove.new()
		self.FrameTrove = Trove.new()

		self:HandleStates(OldState, NewState)
	end)

	LocationChanged:Connect(function(OldLocation: Location, NewLocation: Location)
		local StateConnections = self.StateConnections

		StateConnections:Clean()
		self.StateConnections = Trove.new()

		self:HandleLocations(OldLocation, NewLocation)
	end)
end

function ToolUIManager.HandleLocations(self: UIManager, OldLocation: Location, NewLocation: Location)
	repeat
		task.wait()
	until InventoryController

	print(self)

	local State = self.State
	local OldFrame = self.UIFrame
	local ToolConfigure = self.ToolConfigure
	local FrameTrove = self.FrameTrove

	local Tool = ToolConfigure:GetTool() :: Tool

	local NewFrame : Frame

	if NewLocation == "Hotbar" then
		if OldLocation == "Backpack" and OldFrame then
			OldFrame:Destroy()
		end

		local HotbarLocation = InventoryController.GetHotbarLocation(ToolConfigure)
		local HotbarSlot = InventoryController.GetHotbarSlot(HotbarLocation)

		print(HotbarLocation, HotbarSlot)

		local Selected: Frame, Button: TextButton, Gradient: UIGradient = InventoryController.GetSlotComponents(HotbarSlot)
		local ToolSettings = ToolConfigure:GetToolSettings()

		Gradient.Color = ToolSettings.Gradient
		Gradient.Rotation = ToolSettings.GradientRotation

		Button.Text = Tool.Name
		Button.Font = ToolSettings.Font

		FrameTrove:Connect(Button.MouseButton1Up, function()
			if self.State == "Idle" then
				ToolConfigure:Equip()
			end
		end)

		self.UIFrame = HotbarSlot
		HotbarSlot.Visible = true

		self.State = "Idle"
	elseif NewLocation == "Backpack" then
		if OldLocation == "Hotbar" and OldFrame then
			InventoryController.ClearHotbarFrame()
		end

		if OldLocation == "Backpack" and OldFrame then
			OldFrame:Destroy()
		end

		local BackpackLocation = InventoryController.GetBackpackLocation(ToolConfigure)

		local NewFrame = BackpackTemplate:Clone()

		local Selected: Frame, Button: TextButton, Gradient: Frame = InventoryController.GetBackpackSlotComponents(NewFrame)
		local ToolSettings = ToolConfigure:GetToolSettings()

		Gradient.Color = ToolSettings.Gradient
		Gradient.Rotation = ToolSettings.GradientRotation

		Button.Text = Tool.Name
		Button.Font = ToolSettings.Font

		FrameTrove:Connect(Button.MouseButton1Down, function()
			if Dragging.IsDragging() then
				return
			end
			
			print("D")
			local Start = tick()
			local Time = 0
			
			local Connection
			
			Connection = RunService.PreRender:Connect(function(DeltaTime)
				if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
					Time += DeltaTime
					
					if Time >= 0.2 then
						Connection:Disconnect()
						
						self:ChangeState("Drag")
					end
				else
					Connection:Disconnect()
				end
			end)
		end)

		FrameTrove:Connect(Button.MouseButton1Up, function()
			print("U")
			
			if self.State == "Idle" and not Dragging.IsDragging() then
				ToolConfigure:Equip()
			end
		end)
		
		FrameTrove:Connect(UserInputService.InputEnded, function(Input: InputObject)
			print(Input.KeyCode, Input.UserInputType, self.UIFrame.Name)
			
			if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
				print("mousebutton1", self.UIFrame.Name)
				print(self.State)
				if self.State == "Drag" then
					print("chaning idle")
					self:ChangeState("Idle")
				end
			end
		end)
		
		FrameTrove:Connect(UserInputService.WindowFocusReleased, function()
			print(self.State, self.UIFrame.Name)
			if self.State == "Drag" then
				self:ChangeState("Idle")
			end
		end)
		
		NewFrame.Name = Tool.Name

		self.UIFrame = NewFrame

		NewFrame.LayoutOrder = BackpackLocation
		NewFrame.Visible = true

		NewFrame.Parent = BackpackHolder

		self.State = "Idle"
	end
end

function ToolUIManager.HandleStates(self: UIManager, OldState: State, NewState: State)
	local Location = self.Location
	local UIFrame = self.UIFrame

	local StateConnections = self.StateConnections

	--[[
		local ParentAbsolute = BackpackFrame.AbsolutePosition
		local GuiInset = GuiService:GetGuiInset()

		DragConnections:Connect(RunService.PreRender, function()
			local MouseLocation = UserInputService:GetMouseLocation()
			local Relative = MouseLocation - ParentAbsolute - GuiInset

			Frame.Position = UDim2.fromOffset(Relative.X - (Frame.AbsoluteSize / 2).X, Relative.Y - (Frame.AbsoluteSize / 2).Y)

			if Frame.Parent ~= BackpackFrame then
				Frame.Parent = BackpackFrame
			end
		end)
	]]

	if NewState == "Drag" then
		InventoryController.LockBackpack(self.Identifier)
		Dragging.Add(self.Identifier)
		
		if Location == "Backpack" then
			UIFrame.Parent = BackpackFrame

			local Tween = TweenService:Create(UIFrame, TweenInfo.new(0.05, Enum.EasingStyle.Sine), {
				Rotation = -15,
				Size = UDim2.new(0.093 * 1.1, 0, 0.207 * 1.1, 0)
			})

			Tween:Play()

			local ParentAbsolutePos = BackpackFrame.AbsolutePosition
			local GuiInset = GuiService:GetGuiInset()

			task.spawn(function()
				StateConnections:Connect(RunService.PreRender, function(DeltaTime)
					local MouseLocation = UserInputService:GetMouseLocation()
					local Position = MouseLocation - ParentAbsolutePos - GuiInset

					local Center = UIFrame.AbsoluteSize / 2

					UIFrame.Position = UDim2.fromOffset(Position.X - Center.X, Position.Y - Center.Y)
				end)
			end)
		end
	elseif NewState == "Idle" then
		InventoryController.UnlockBackpack(self.Identifier)
		Dragging.Remove(self.Identifier)
		
		if Location == "Backpack" then
			UIFrame.Size = UDim2.new(0.093, 0, 0.207, 0)
			UIFrame.Rotation = 0
			
			UIFrame.Parent = BackpackHolder
		end
	end
end

function ToolUIManager.ChangeState(self: UIManager, State: State)
	local StateChanged = self.StateChanged
	local OldState = self.State

	self.State = State
	StateChanged:Fire(OldState, State)
end

function ToolUIManager.ChangeLocation(self: UIManager, Location: Location)
	local LocationChanged = self.LocationChanged
	local OldLocation = self.Location

	self.Location = Location
	LocationChanged:Fire(OldLocation, Location)
end

function ToolUIManager.Destroy(self: UIManager)
	local UIFrame = self.UIFrame
	local Location = self.Location
	
	local FrameTrove = self.FrameTrove
	local StateTrove = self.StateConnections
	
	StateTrove:Clean()
	FrameTrove:Clean()

	if Location == "Backpack" then
		UIFrame:Destroy()
	else
		InventoryController.ClearHotbarFrame(UIFrame)
	end
end

return ToolUIManager

the connection is being made at HandleLocations function inside the if statement where i check if the location is the backpack
the dragging happens at HandleStates function inside the if statement where i check if its location is backpack and the state is drag

whenever i let go of the left mouse button it does fire for other backpack frames that arent being dragged but the dragged one does , i tried everything even removing all of the frames contents and setting interactable to false, nothing works

i figured it out, its because im clearing the frametrove while changing the state