Attemping to check if a player has a tool in their backpack

Hello, I’m trying to check if a player has a tool (from a list) in their backpack. I know how to check their backpack for a single tool, but I want this to check if the player has any of the tools written in the list. Is there a way to do this? My code is below:

clickDetector.MouseClick:Connect(function(player)
	if open.Value == false and debounce == false then
		if player.Backpack:FindFirstChild(clearance) then
			debounce = true
			DoorOpen()
			task.wait(1)
			debounce = false
		else
			--Put the beep noise here etc
		end

The clearance array looks like this:

local clearance = {
	"Level 2",
	"Level 3"
}

Thanks in advance.

Add a for loop to iterate through all tools you want to check for around the if-statement.

clickDetector.MouseClick:Connect(function(player)
	if open.Value == false and debounce == false then
		local hasAccess = false
		for _, clearanceTool in pairs(clearance) do
			if player.Backpack:FindFirstChild(clearanceTool) then
				hasAccess = true
				break -- Stop the loop once one of them is found
			end
		end
		if hasAccess then
			debounce = true
			DoorOpen()
			task.wait(1)
			debounce = false
		else
			-- Beep noise etc
		end
end)
1 Like

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