local function G(G)local v=mFrame.Parent local S=game.ReplicatedStorage.Prefabs local d=S.ItemSlot local u=d:Clone()u.Parent=v u.equip.Text=G.Name u.ItemName.Value=G.Name G:Destroy()end local function v()for v,S in pairs(char:GetChildren())do if S:IsA("\084\111\111\108")then G(S)end end for v,S in pairs(plr.Backpack:GetChildren())do if S:IsA("\084\111\111\108")then G(S)end end local v=game.ReplicatedStorage.ItemRegistry local S=v:FindFirstChild(value_item.Value)local d=S:Clone()d.Parent=plr.Backpack mFrame:Destroy()end


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
