How would I make a TextLabel that shows how many tools i have in my backpack/hotbar

I have a surfaceGui and was wondering how I could make the middle textlabel show how many items are in my backpack/hotbar


I couldn’t find any docs, forum posts, videos, or basically anything mentioning how to do it.

If anyone can give me some docs or a video explaining how to do this, I would really appreciate it

2 Likes

Quickly written but this should get the job done:

local Player = game:GetService('Players').LocalPlayer
local Backpack = Player.Backpack

function GetToolsCount()
	local Count = 0
	for _,v in {unpack(Backpack:GetChildren()), unpack(Player.Character:GetChildren())} do
		if v.ClassName == 'Tool' then
			Count+=1
		end
	end
	return Count
end

So I got it to work on normal ScreenGui but it doesn’t seem to work on SurfaceGui

heres my code

local Player = game:GetService("Players").LocalPlayer
local Backpack = Player:WaitForChild("Backpack")
local Character = Player.Character or Player.CharacterAdded:Wait()
local TextLabel = script.Parent

local function GetToolsCount()
	local Count = 0
	for _, v in ipairs(Backpack:GetChildren()) do
		if v:IsA("Tool") then
			Count += 1
		end
	end
	for _, v in ipairs(Character:GetChildren()) do
		if v:IsA("Tool") then
			Count += 1
		end
	end
	return Count
end

local function UpdateLabel()
	TextLabel.Text = "Tools: " .. GetToolsCount()
end

Backpack.ChildAdded:Connect(UpdateLabel)
Backpack.ChildRemoved:Connect(UpdateLabel)
Character.ChildAdded:Connect(UpdateLabel)
Character.ChildRemoved:Connect(UpdateLabel)

Player.CharacterAdded:Connect(function(newChar)
	Character = newChar
	Character.ChildAdded:Connect(UpdateLabel)
	Character.ChildRemoved:Connect(UpdateLabel)
	UpdateLabel()
end)

UpdateLabel()
1 Like
--28.09.2025 - 23:07 : 55

local Players = game:GetService("Players")
local ScreenGui = Instance.new("ScreenGui") do
	ScreenGui.IgnoreGuiInset = true
	ScreenGui.ResetOnSpawn = false
	ScreenGui.ScreenInsets = Enum.ScreenInsets.None
	ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
end
--[Children] {
	local TextLabel = Instance.new("TextLabel") do
		TextLabel.AnchorPoint = Vector2.one
		TextLabel.BackgroundColor3 = Color3.new(1,1,1)
		TextLabel.BackgroundTransparency = 1
		TextLabel.BorderColor3 = Color3.new(0,0,0)
		TextLabel.BorderSizePixel = 0
		TextLabel.FontFace = Font.new("rbxasset://fonts/families/SourceSansPro.json",Enum.FontWeight.Regular,Enum.FontStyle.Normal)
		TextLabel.Position = UDim2.new(1,0,1,0)
		TextLabel.Size = UDim2.new(0,87,0,104)
		TextLabel.Text = "0"
		TextLabel.TextColor3 = Color3.new(1,1,1)
		TextLabel.TextScaled = true
		TextLabel.TextSize = 14
		TextLabel.TextWrapped = true
		Instance.new("UIAspectRatioConstraint",TextLabel)
		TextLabel.Parent = ScreenGui
	end
--}

local plr = Players.LocalPlayer::Player


local PlayerGui = plr:WaitForChild("PlayerGui")::PlayerGui
local function CharAdded(char:Model):()
	local backpack = plr:WaitForChild("Backpack")::Backpack
	local function UpdateCount():()
		TextLabel.Text = tostring(#backpack:GetChildren()+((char:FindFirstChildOfClass("Tool") and 1) or 0))
	end
	backpack.ChildAdded:Connect(UpdateCount)
	backpack.ChildRemoved:Connect(UpdateCount)
	UpdateCount()
end
plr.CharacterAdded:Connect(CharAdded)
local char = plr.Character::Model?
if char then CharAdded(char) end




ScreenGui.Parent=PlayerGui


1 Like

I got this to work on a screenGui with this code

local Players = game:GetService("Players")
local TextLabel = script.Parent
local plr = Players.LocalPlayer::Player


local PlayerGui = plr:WaitForChild("PlayerGui")::PlayerGui
local function CharAdded(char:Model):()
	local backpack = plr:WaitForChild("Backpack")::Backpack
	local function UpdateCount():()
		TextLabel.Text = tostring(#backpack:GetChildren()+((char:FindFirstChildOfClass("Tool") and 1) or 0))
	end
	backpack.ChildAdded:Connect(UpdateCount)
	backpack.ChildRemoved:Connect(UpdateCount)
	UpdateCount()
end
plr.CharacterAdded:Connect(CharAdded)
local char = plr.Character::Model?
if char then CharAdded(char) end

but I could not get it to work on a surfaceGui and I can’t figure out why
here’s the layout

its not that hard just ask me I’ll help you

try testing this script, place it in a Script, and change the RunContext (on script properties) to “Client” and place the script inside the TextLabel

local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local Backpack = LocalPlayer:WaitForChild("Backpack") :: Backpack
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

local TextLabel = script.Parent
local MaxTools = 38

local function UpdateToolsCount(Tool: Tool)
	if Tool ~= nil then
		if not Tool:IsA('Tool') then return end
	end
	
	task.defer(function()
		local BackpackTools = #Backpack:GetChildren()
		local CharacterTool = Character:FindFirstChildWhichIsA('Tool') and 1 or 0
		
		TextLabel.Text = `{BackpackTools + CharacterTool}/{MaxTools}`
	end)
end

Backpack.ChildAdded:Connect(UpdateToolsCount)
Backpack.ChildRemoved:Connect(UpdateToolsCount)
Character.ChildAdded:Connect(UpdateToolsCount)

UpdateToolsCount(nil)

yes please! this is the script i have right now

local Player = game:GetService("Players").LocalPlayer
local Backpack = Player:WaitForChild("Backpack")
local Character = Player.Character or Player.CharacterAdded:Wait()
local TextLabel = script.Parent

local function GetToolsCount()
	local Count = 0
	for _, v in ipairs(Backpack:GetChildren()) do
		if v:IsA("Tool") then
			Count += 1
		end
	end
	for _, v in ipairs(Character:GetChildren()) do
		if v:IsA("Tool") then
			Count += 1
		end
	end
	return Count
end

local function UpdateLabel()
	TextLabel.Text = "Tools: " .. GetToolsCount()
end

Backpack.ChildAdded:Connect(UpdateLabel)
Backpack.ChildRemoved:Connect(UpdateLabel)
Character.ChildAdded:Connect(UpdateLabel)
Character.ChildRemoved:Connect(UpdateLabel)

Player.CharacterAdded:Connect(function(newChar)
	Character = newChar
	Character.ChildAdded:Connect(UpdateLabel)
	Character.ChildRemoved:Connect(UpdateLabel)
	UpdateLabel()
end)

UpdateLabel()

and it works on textlabels in screenguis but not in any surfaceguis i make

still doesn’t work on surfaceGuis, does roblox handle those differently on the client?

Put the LocalScript in StarterGui and edit Surface gui from there

1 Like

Also if ur using ChildAdded and ChildRemoved, the might aswell not use GetToolsCount and just have a counter like u have right there and increment / decrement on those events.

Thank you! I was trying to figure this out for like two days

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.