How to sort tools to slots 1-4 for custom hotbar?

How can I sort tools like Bloxy Cola, Sword, Fireball, and Slingshot into specific slots (Slot 1, Slot 2, etc.) after the player receives them in their backpack?
When I press a number, the tool equips correctly, but if I equip other tools and then equip the first tool again, it changes its slot.

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
local player = game.Players.LocalPlayer
local plrser = game:GetService("Players")
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
local bp = player.Backpack
local uis = game:GetService("UserInputService")
local bpGui = player.PlayerGui.BPgui

local slots = {
	["Slot1"] = bpGui.Frame.Slot1,
	["Slot2"] = bpGui.Frame.Slot2,
	["Slot3"] = bpGui.Frame.Slot3,
	["Slot4"] = bpGui.Frame.Slot4
}

local inputs = {
	["One"] = Enum.KeyCode.One,
	["Two"] = Enum.KeyCode.Two,
	["Three"] = Enum.KeyCode.Three,
	["Four"] = Enum.KeyCode.Four
}

local function sortToolsByName(tools)
	table.sort(tools, function(a, b)
		return a.Name < b.Name
	end)
	return tools
end

local currentTool = nil

local function toolHandle(key)
if player.Character then
tools = bp:GetChildren()
tools = sortToolsByName(tools)
end
	local tooltoequip = nil
	if key == inputs.One then
		tooltoequip = tools[1]
		for _, slot in pairs(slots) do
			slot.ImageColor3 = Color3.fromRGB(255,255,255)
		end
		slots.Slot1.ImageColor3 = Color3.fromRGB(255,0,0)
	elseif key == inputs.Two then
		tooltoequip = tools[2]
		for _, slot in pairs(slots) do
			slot.ImageColor3 = Color3.fromRGB(255,255,255)
		end
		slots.Slot2.ImageColor3 = Color3.fromRGB(255,0,0)
	elseif key == inputs.Three then
		tooltoequip = tools[3]
		for _, slot in pairs(slots) do
			slot.ImageColor3 = Color3.fromRGB(255,255,255)
		end
		slots.Slot3.ImageColor3 = Color3.fromRGB(255,0,0)
	elseif key == inputs.Four then
		tooltoequip = tools[4]
		for _, slot in pairs(slots) do
			slot.ImageColor3 = Color3.fromRGB(255,255,255)
		end
		slots.Slot4.ImageColor3 = Color3.fromRGB(255,0,0)
	end


	if tooltoequip then
		if currentTool == tooltoequip then
			hum:UnequipTools()
			currentTool = nil
		else
			if currentTool then
				hum:UnequipTools()
			end
			hum:EquipTool(tooltoequip) 
			currentTool = tooltoequip 
		end
	end
end

uis.InputBegan:Connect(function(input, busy)
	if busy then return end
	for _, keycode in pairs(inputs) do
		if input.KeyCode == keycode then
			toolHandle(input.KeyCode)
		end
	end
end)

You should use a dictionary for this. Have each index store the tool to equip


local tools = {}

local activeSlot: ImageLabel
local function equip(index)
     -- this if statement is equivalent to the previous slot
     if activeSlot then
         -- change color to unequipped
     end
     hum:UnequipTools()
     task.defer(hum.EquipTool, hum, tools[index])
     -- this would be the current slot
     -- change color to equipped
     activeSlot = newSlot
end