Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to find your players tools in backpack via workspace?

local player = game.Players:GetPlayerFromCharacter(chara)

local backpack = player:FindFirstChild("Backpack")

1 answer

Hello.

Tools in a player's backpack are stored in game.Players[player.Name].Backpack. Here's a Script to check player tools:

function CheckTools(player)
	for _, v in pairs(player:FindFirstChild("Backpack"):GetChildren()) do
		if v:IsA("Tool") then
			print("I found a tool! The tool name is: " ..v.Name)
		end
	end
	print("Found a total of " ..#player:FindFirstChild("Backpack"):GetChildren().. " tools!")
end

-- We made a function to check player tools. Any :GetChildren() is a table. I used # to get the table number. (How many items are in the table.)

game.Players.PlayerAdded:Connect(function(player)
	-- The player has 0 tools.
	CheckTools(player)
	print("Waiting 2 seconds!")
	wait(2)
	-- Let's add some tools and try again.
	local Tool1 = Instance.new("Tool", player.Backpack)
	Tool1.RequiresHandle = false
	Tool1.Name = "My Tool"
	
	local Tool2 = Instance.new("Tool", player.Backpack)
	Tool2.RequiresHandle = false
	Tool2.Name = "A tooooool"
	CheckTools(player)
end)

Output:

Found a total of 0 tools!

Waiting 2 seconds!

I found a tool! The tool name is: My Tool

I found a tool! The tool name is: A tooooool

Found a total of 2 tools!

https://imgur.com/a/JiSdnvG

This discussion is preserved as it was. New answers, comments, and votes are closed.