Custom Backpack Issue | Swapping items without unequipping the current one first

Hi!

  1. What do you want to achieve? This issue is currently part of something bigger, a redesign of the CoreGui based on the 2014L CoreGui. This issue is regarding the backpack; I want to make it so when you are holding an item, you can click on another and just switch.

  2. What is the issue? It’s quite buggy and I frankly don’t know how to fix it. Right now it lets you swap, but you need to click one twice afterwards to make it work again.

  3. What solutions have you tried so far? I’ve rewritten this script a few times to try and get it to work, but I simply cannot figure out what I need to change.

Here’s my equip/unequip code:

--Variables
local tweenService = game:GetService("TweenService")
local holding = script.Parent.Parent.Parent.EquippedV.Value
local plr = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local char = plr.Character
local humanoid = char:WaitForChild("Humanoid")
local backpack = plr:WaitForChild("Backpack")

--Functions
function makeLarger(uielm)
	local goal = {}
	goal.Size = UDim2.new(0, 77, 0, 77)
	goal.Position = UDim2.new(0,-3,0,-3)

	local tweenInfo = TweenInfo.new(.2)

	local tween = tweenService:Create(uielm, tweenInfo, goal)

	tween:Play()
end

function makeSmaller(uielm)
	local goal = {}
	goal.Size = UDim2.new(0, 72, 0, 72)
	goal.Position = UDim2.new(0, 0, 0, 0)

	local tweenInfo = TweenInfo.new(.2)

	local tween = tweenService:Create(uielm, tweenInfo, goal)

	tween:Play()
end

function ActivateTool()
	for i,e in pairs(script.Parent.Parent.Parent.Parent:GetChildren()) do
		if e:IsA("Frame") then
			makeSmaller(e.Icon)
			e.EquippedV.Value = false
		end
	end
	holding = true
	makeLarger(script.Parent.Parent)
	humanoid:EquipTool(backpack[script.Parent.Parent.Parent.Name])
end

function DeactivateTool()
	for i,e in pairs(script.Parent.Parent.Parent.Parent:GetChildren()) do
		if e:IsA("Frame") then
			makeSmaller(e.Icon)
			e.EquippedV.Value = false
			print(e.Name..".EquippedV.Value = "..tostring(e.EquippedV.Value))
			print("------------------------------------------------")
		end
	end
	holding = false
	makeSmaller(script.Parent.Parent)
	humanoid:UnequipTools()
end

function onClick()
	print("Clicked. Holding inside of the "..script.Parent.Parent.Parent.Name.." instance is "..tostring(holding))
	print("------------------------------------------------")
	if holding == false then
		ActivateTool()
	else
		DeactivateTool()
	end
end

--Activation
script.Parent.MouseButton1Click:Connect(onClick)

Here’s the structure of the UI elements:
[Item Button Template]
image

[Main UI Structure (only includes parts important to the issue, if you want to see BackpackHandler then I will show you, but it isnt needed.)]
image

and here’s a video of the bug:
(I had to use YouTube because the DevForum would not let me upload the video.)

Thanks!