Tool detection issues

I have tried to make a script that detects whether or not a player has a tool with a certain in their inventory or not. It finds the correct tool and activates the function, but the issue is it also searches for tools that have a different name and then activates both functions at once. I realise this is probably because of the GetChildren, so is there any way I can get a script to stop searching for the tool when it finds it?

for _, tool in pairs(player.Backpack:GetChildren()) do
		if tool.Name == "key6" and debounce == false then

			if isOpen == false then open() else close() end
		
		elseif tool.Name ~= "key6" and debounce == false then
			debounce = true
			
			script.Parent.deny:Play()
			
			debounce = false
		end
	end

thank you in advance

1 Like

break
Loops (roblox.com)


1 Like

set a value to false outside the loop, make it loop through and set the value to true if it finds it, then after the loop, check if the value is still false (not found) or true (found)

2 Likes

what section should i look at?

yeah this works for me thank you very much!! :smiley: