How do I make a code that allows the player to only have one tool?

what I want to happen is when the player already has a tool in their Backpack and they buy a new tool, the original tool will be put into their inventory folder located in their gui.

So basically you buy a tool and your original to gets put into folder for you to use your new tool you just bought!

My script I need to add code to:

local Players = game:GetService("Players")

local replicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer

local Frame = script.Parent.Frame

local Items = Frame.Items

local Info = Frame.Info

local buy = Info.Buy

local exit = Frame.Exit

local functionDebounce = false

local errorValue = false

local function shopError()
	errorValue = true
	buy.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	buy.Text = "Error"
	Info.ItemPrice.Text = ""
	Info.ItemName.Text = ""
end

local function setData(TextButton)
	if not TextButton:FindFirstChild("Price") or not TextButton:FindFirstChild("Image") or not TextButton:FindFirstChild("ItemName") then errorValue() end
	if TextButton:FindFirstChild("Price") and TextButton:FindFirstChild("Image") and TextButton:FindFirstChild("ItemName") then
		errorValue = false
		buy.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
		buy.Text = "Purchase"
		Info.ItemPrice.Text = TextButton.Price.Value
		Info.ItemName.Text = TextButton.ItemName.Value
	end
end

local function notEnough(index)
	if functionDebounce == false then
		functionDebounce = true
		index.BackgroundColor3 = Color3.fromRGB(255,0,0)
		index.Text = "NotEnough"
		task.wait(2)
		if errorValue == false then
			index.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
			index.Text = "Purchase"
		end	
		functionDebounce = false
	end
end

local function alreadyHas(index)
	if functionDebounce == false then
		functionDebounce = true
		index.BackgroundColor3 = Color3.fromRGB(0, 0, 255)
		index.Text = "Already Owned"
		task.wait(2)
		if errorValue == false then
			index.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
			index.Text = "Purchase"
		end	
		functionDebounce = false
	end
end

local function removeValues(index)
	Frame.Visible = false
	index.ItemPrice.Text = ""
	index.ItemName.Text = ""
end

buy.MouseButton1Click:Connect(function()
	if Info.ItemImage.Image ~= "" and Info.ItemPrice.Text ~= "" and Info.ItemName.Text ~= "" then
		if not player.Backpack:FindFirstChild(Info.ItemName.Text) then
			
			if player.leaderstats.Fishes.Value >= tonumber(Info.ItemPrice.Text) then
				
				replicatedStorage.ShopEvent:FireServer(Info.ItemName.Text, Info.ItemPrice.Text)
				
				if errorValue == false and functionDebounce == false then
					buy.Text = "Successful!"
				end
				task.wait(2)
				
				if errorValue == true or functionDebounce == true then
					buy.Text = "Error"
				else
					buy.Text = "Purchase"
				end
				
			else if player.leaderstats.Fishes.Value <= tonumber(Info.ItemPrice.Text) then
					notEnough(buy)
				end
			end
			
		elseif player.Backpack:FindFirstChild(Info.ItemName.Text) then
			alreadyHas(buy)
		end
	end
end)

exit.MouseButton1Click:Connect(function()
	removeValues()
end)

replicatedStorage.ShopEvent.OnClientEvent:Connect(function(Argument)
	if not Argument then return end
	if Argument == "Open" then
		Frame.Visible = true
	end
end)

for _, v in pairs(Items:GetChildren()) do
	v.MouseButton1Click:Connect(function()
		setData(v)
	end)
end

the folder:
DevForum fishing folder

You could disable the core GUI of the roblox inventory, thus you have the freedom to use userinputservice, where you could only bind key 1 to equip an Item. The backpack will remain, and you can still equip a tool using tool:Equip(). There are other ways, but this one is just straight foward, and works well with your custom gui