-- Functions


local function onRenderStepped()
	-- Adjust main frame canvas size based on amount of items.
	
	local uiGridLayout = iContainer.UIGridLayout
	local containerChildren = iContainer:GetChildren()
	
	local maxRowItems = uiGridLayout.FillDirectionMaxCells
	local rowCount = math.ceil((#containerChildren - 1) / maxRowItems)
	
	local totalHeight = ((uiGridLayout.CellSize.Y.Offset) + (uiGridLayout.CellPadding.Y.Offset * 2)) * rowCount
	
	iContainer.Size = UDim2.new(0.8,0, 0,totalHeight)
	
	mFrame.CanvasSize = UDim2.new(0, mFrame.CanvasSize.X.Offset, 0, iContainer.Size.Y.Offset + 100)
	
	-- Get amount of tools player owns
	
	local toolsFound = {}
	
	for i, obj in pairs(char:GetChildren()) do
		if obj:IsA("Tool") then
			currentTool = obj
			table.insert(toolsFound, obj)
			
		end
	end
	
	for i, obj in pairs(plr.Backpack:GetChildren()) do
		if obj:IsA("Tool") then	
			table.insert(toolsFound, obj)
			
		end
	end
	
	print(#toolsFound)
	
	-- If player has more than 1 tool in his character. . .
	
	if #toolsFound > 1 then
		
		-- Transport second item to inventory storage
		
		local toolToTransfer = toolsFound[1]
		
		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
		
		-- Remove tool from existence
		
		toolToTransfer:Destroy()
		
	end
	
	-- Reset table
	
	table.clear(toolsFound)
	
end
