How to detect a tool in player's backpack

Is there a way (using a proximity prompt primarily) to check if a certain tool is in the player’s backpack?

Any help is appreciated!

local ProxPrompt = --Your Prox Prompt
local ToolName - --Toolname to check for
ProxPrompt.Triggered:Connect(function(PlayerWhoTriggered)
    for i, tool in pairs(PlayerWhoTriggered.Backpack:GetChildren()) do
       if tool.Name == ToolName then
          print("Tool exists")
       end
    end
end)

2 Likes

Well, @10kgoldxdrip’s first one will work, but it could be simpler like this:

local ProxPrompt = --Your Proximity Prompt
local ToolName = --Toolname to check for
ProxPrompt.Triggered:Connect(function(player))
    local tool = player.Backpack:FindFirstChild(ToolName)
    
    if tool then
        --has tool
    end
end)

The 1st and 2nd functions don’t work. There are no errors, but it doesn’t end up printing the “Tool exists”

The 2nd one doesn’t work, but I do think the first one does.

This is what I did

local Prompt = script.Parent.ProximityPrompt
local Tool = "Wrench"

Prompt.Triggered:Connect(function(player)
	--
	for i, tool in pairs(player.Backpack:GetChildren()) do
		if tool.Name == Tool.Name then
			print("Player has Wrench")
		else
			print("Player does not have Wrench")
		end
	end
	--
end)

It prints “Player does not have Wrench”
So maybe I did something wrong with the locals?

Only add Tool instead of Tool.Name.

That works!

But now it only works when the player has it unequipped, how should I fix that?

Loop through the Charater using the same method.

Everyone keep’s forgetting to check the character for the tool because when you hold a tool it goes into their character.

Proxy.Triggered:Connect(function(Plr)
    if Plr.Backpack:FindFirstChild('Wrench') or Plr.Character:FindFirstChild('Wrench') then
        -- Player has wrench!
    else
        -- Player does not have wrench!
    end
end)
1 Like

Why loop through the character? You can just use :FindFirstChild().

The “First Method” does looping, I do still acknowledge FindFirstChild to be more readable.

Oh wow this worked, I didn’t know that the tool goes into the Character. Thank you so much!

1 Like

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