BLOXBUILDS
Discord
Back
UI/UX

Basic Inventory

Paste into StarterPlayerScripts as a LocalScript. Shows the tools in the backpack as slots. Clicking a slot equips or unequips that tool.

-- Paste into StarterPlayer > StarterPlayerScripts as a LocalScript.

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local gui = Instance.new("ScreenGui")
gui.Name = "Inventory"
gui.ResetOnSpawn = false
gui.Parent = player:WaitForChild("PlayerGui")

local panel = Instance.new("Frame")
panel.AnchorPoint = Vector2.new(0.5, 1)
panel.Position = UDim2.new(0.5, 0, 1, -20)
panel.Size = UDim2.fromOffset(420, 72)
panel.BackgroundColor3 = Color3.fromRGB(19, 22, 28)
panel.Parent = gui

local layout = Instance.new("UIListLayout")
layout.FillDirection = Enum.FillDirection.Horizontal
layout.Padding = UDim.new(0, 8)
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.VerticalAlignment = Enum.VerticalAlignment.Center
layout.Parent = panel

local function tools(): { Tool }
	local list: { Tool } = {}
	local backpack = player:FindFirstChildOfClass("Backpack")
	local character = player.Character
	if backpack then
		for _, child in ipairs(backpack:GetChildren()) do
			if child:IsA("Tool") then
				table.insert(list, child)
			end
		end
	end
	if character then
		for _, child in ipairs(character:GetChildren()) do
			if child:IsA("Tool") then
				table.insert(list, child)
			end
		end
	end
	return list
end

local function render()
	for _, child in ipairs(panel:GetChildren()) do
		if child:IsA("TextButton") then
			child:Destroy()
		end
	end

	local character = player.Character
	local humanoid = character and character:FindFirstChildOfClass("Humanoid")
	for _, tool in ipairs(tools()) do
		local button = Instance.new("TextButton")
		button.Size = UDim2.fromOffset(96, 48)
		button.BackgroundColor3 = if tool.Parent == character then Color3.fromRGB(99, 102, 241) else Color3.fromRGB(30, 35, 48)
		button.Text = tool.Name
		button.TextColor3 = Color3.new(1, 1, 1)
		button.Font = Enum.Font.GothamBold
		button.TextSize = 14
		button.Parent = panel

		button.MouseButton1Click:Connect(function()
			if not humanoid then
				return
			end
			if tool.Parent == character then
				humanoid:UnequipTools()
			else
				humanoid:EquipTool(tool)
			end
		end)
	end
end

local function watch(container: Instance)
	container.ChildAdded:Connect(render)
	container.ChildRemoved:Connect(render)
end

player.ChildAdded:Connect(function(child)
	if child:IsA("Backpack") then
		watch(child)
		render()
	end
end)

player.CharacterAdded:Connect(function(character)
	watch(character)
	render()
end)

local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
	watch(backpack)
end
if player.Character then
	watch(player.Character)
end
render()