Making an inventory system with equip P2

So yeah, If you have seen my previous post, it seemed complicated
Well now, I have come up with a better idea on how to do this

So there is a GUI with pictures of items that youve got
You equip one tool, that tool gets set to ServerStorage
The previous tool you equipped, is not in ServerStorage
You can only equip one item at a time, you cannot equip no Items

I have the GUI, with the images and stuff, I just dont know how to edit the script
feel free to edit the script, and I can tell you any info you need


local player = game.Players.LocalPlayer
local character = player.Character
local items = {}
local buttons = {}
local ListaGui = script.Parent.Frame.ScrollingFrame
local EquipGui = script.Parent.Frame.Equipar


game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) 


function buscar(location)
	for i,v in pairs(location:GetChildren()) do 
		if v:isA("Tool") then 
			table.insert(items,v)
		end
	end
end

function actualizar()
	for i,v in pairs(buttons) do 
		v:Destroy() 
	end

	
	for i,item in pairs(items) do
		local button = script.Button:Clone() 
		button.Name = item.Name 
		button.LayoutOrder = i
		button.Parent = ListaGui 
		button.Image = item.TextureId 
		button.BackgroundTransparency = 1
		table.insert(buttons,button) 
		button.MouseButton1Click:connect(function()
			local ListaGui = script.Parent.Frame.ScrollingFrame
			local EquipGui = script.Parent.Frame.Equipar
			if ListaGui.Selected.Value == nil or ListaGui.Selected.Value ~= item then 
				
				EquipGui.ItemName.Text = item.Name
				EquipGui.ImageLabel.Image = item.TextureId 
				ListaGui.Selected.Value = item
				if ListaGui.Selected.Value ~= ListaGui.Equipped.Value then 
					ListaGui.Location.Value = item.Parent 
					EquipGui.Equip.Text = "Equip" 
				elseif ListaGui.Selected.Value == ListaGui.Equipped.Value then 
					ListaGui.Location.Value = item.Parent
					EquipGui.Equip.Text = "Unequip"
				end
			end
		end)
	end
end



function backpackRefresh()
	items = {}
	buscar(character)
	buscar(player.Backpack)
	actualizar()
end

backpackRefresh()

player.Backpack.ChildAdded:connect(backpackRefresh)
player.Backpack.ChildRemoved:connect(backpackRefresh)

character.ChildAdded:connect(backpackRefresh)
character.ChildRemoved:connect(backpackRefresh)




local EquipButton = EquipGui.Equip

EquipButton.MouseButton1Click:connect(function()
	
	local equipped = ListaGui.Equipped
	local selected =  ListaGui.Selected
	local location =  ListaGui.Location
	local player = game.Players.LocalPlayer
	local character = player.Character
	if equipped.Value == nil or equipped.Value ~= selected.Value then 
		character.Humanoid:UnequipTools() 
		if location.Value == player.Backpack then
			character.Humanoid:EquipTool(selected.Value)
			equipped.Value = selected.Value
			EquipButton.Text = "Unequip"
		end
	else
		character.Humanoid:UnequipTools()
		equipped.Value = nil
		EquipButton.Text = "Equip"
	end
end)

If you could help me, that would make my game, whats the word, half done (that was 2 oops)

Thanks for reading!!!

Personally how i would do this is create a string value or even an object value inside the player and name it “Tool” when player clicks a gui, set the “Tool” value to whatever tool was chosen, when the match starts, just give the tool to the player according to the “Tool” value

Well, I kinda scrapped it already, so this doesnt need to be solved

But thanks