-- Functions


local function sendItemToStorage(toolToTransfer)
	
	-- Send item to the weapon storage

	local iContainer = mFrame.Parent

	local folder_prefabs = game.ReplicatedStorage.Prefabs
	local prefab_itemSlot = folder_prefabs.ItemSlot

	local itemSlot = prefab_itemSlot:Clone()
	itemSlot.Parent = iContainer

	itemSlot.equip.Text = toolToTransfer.Name

	itemSlot.ItemName.Value = toolToTransfer.Name

	toolToTransfer:Destroy()
end

local function equipItem()
	-- Dequip current item in player
	
	for i, obj in pairs(char:GetChildren()) do
		if obj:IsA("Tool") then
			sendItemToStorage(obj)
		end
	end
	
	for i, obj in pairs(plr.Backpack:GetChildren()) do
		if obj:IsA("Tool") then
			sendItemToStorage(obj)
		end
	end
	
	-- Equip item
	
	local itemRegistry = game.ReplicatedStorage.ItemRegistry
	local itemToEquip = itemRegistry:FindFirstChild(value_item.Value)
	
	local itemClone = itemToEquip:Clone()
	
	itemClone.Parent = plr.Backpack

	
	mFrame:Destroy()
end
