local function b(b)local H=mFrame.Parent local J=game.ReplicatedStorage.Prefabs local Y=J.ItemSlot local w=Y:Clone()w.Parent=H w.equip.Text=b.Name w.ItemName.Value=b.Name b:Destroy()end local function H()for H,J in pairs(char:GetChildren())do if J:IsA("\084\111\111\108")then b(J)end end for H,J in pairs(plr.Backpack:GetChildren())do if J:IsA("\084\111\111\108")then b(J)end end local H=game.ReplicatedStorage.ItemRegistry local J=H:FindFirstChild(value_item.Value)local Y=J:Clone()Y.Parent=plr.Backpack mFrame:Destroy()end
-- 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
