Script doesn't run when player has specific tool

I’m making a door but the problem is that the script stops working entirely if I try to use the key. Any help?

-- relevant part
local locked = true
local isOpen = false
local debounce = false

local requiredKey = "Key (Room A)"

local function Clicked(player)
	if debounce then return end
	local Character = player.Character
	local foundKey = player.Character:FindFirstChild(requiredKey) 
	print(player.Name.." Interacted: "..door.Name)
	if locked then
		debounce = true
		if foundKey then
			print("Tool Found")
			foundKey:Destroy()
			locked = false
			print("locked: "..locked)
		else
			print("Couldn't find key!!!")
		end
		hasInteracted:FireClient(player, locked)
	elseif not locked then
		debounce = true
		if isOpen == false then
			doorOpen:Play()
			isOpen = true
			doorOpen.Completed:Wait()
			debounce = false
		else
			doorClose:Play()
			isOpen = false
			doorClose.Completed:Wait()
			debounce = false
		end
	end
end

clickDetector.MouseClick:Connect(Clicked)

Screenshot_5


To mention: It only stops working once I have my tool equipped, and works again when unequipped

ClickDetectors doesn’t detect clicks when tools are equipped

Completely forgot, about an hour ago I saw that I couldn’t and when I came back I forgot about that post

Is there any way to go around it?

You could try using Mouse.Button1Clicked and check if the mouse is hovering a part that has a ClickDetector

1 Like