Opening a locked door with a key using ClickDetector

The problem I have right now is when I equip a key and try to click the lock, it doesn’t do anything, but when I unequip it, the script works. I first used the script below but it didn’t do anything when I had the key equipped so I practically deleted it. Did some research and found this topic https://devforum.roblox.com/t/how-to-make-a-door-with-click-detector-key-instead-of-touched-function/1274608 but it didn’t help me out either since they said if you use the Activated event, ClickDetectors would not work. So I’m confused on what I should do?

local function ClickDetectorClicked(player)
  if player.Character and player.Character:FindFirstChild("ToolName") or player.Backpack:FindFirstChild("ToolName") then
    print("valid")
  end
end

part.ClickDetector.MouseClick:Connect(ClickDetectorClicked)

I’m not that experienced but try using else statment

1 Like
local function ClickDetectorClicked(player)
	if player.Parent:FindFirstChild("ToolName") or player.Backpack:FindFirstChild("ToolName") then
		print("valid")
	end
end

script.Parent.ClickDetector.MouseClick:Connect(ClickDetectorClicked)
1 Like

I want to have the key equipped for the person to open the door, not when it’s unequipped.

I used the script you told me to use and basically got the same result

I tried to use your suggestion and nothing happened.

you have to use mouse.target and it will be so hard you should take ez way and use ProximityPrompt to active script

try this and replace clickDetector with ProximityPrompt

local function ClickDetectorClicked(player)
	if player.Character:FindFirstChild("ToolName") or player.Backpack:FindFirstChild("ToolName") then
		print("valid")
	end
end

script.Parent.ProximityPrompt.MouseClick:Connect(ClickDetectorClicked)

try this and replace ClickDetector with ProximityPrompt it way work for you

local function ClickDetectorClicked(player)
	if player.Character:FindFirstChild("ToolName") or player.Backpack:FindFirstChild("ToolName") then
		print("valid")
	end
end

script.Parent.ProximityPrompt.Activated:Connect(ClickDetectorClicked)
3 Likes

yeah that didn’t work either,


imma just do what you said and take the easy way, and just add in a ProximityPrompt and have the script check if the key is in the players backpack.

The problem is when you equip a tool and try to interact with an object has ClickDetector in it, it won’t work. Because the tool blocks out the mouse communication with the ClickDetector. At the moment, there is no properties to disable that. Best you can do is to make a fake ClickDetector by using Mouse.Target checks for the model’s name and do stuff.

3 Likes