So what I am trying to achieve is where you can open a door with a key, but instead of the key colliding into the handle itself, you have to click a clickdetector from the door handle which will cause the door to open(tweened). Problem is, I don’t know how to make it so that the script checks if the player has the key in their inventory or not, and if it doesn’t have a key then a gui will pop-up displaying, “This room requires a key.”
ClickDetector.MouseClick
actually passes the player who clicked as an argument, so you can just check their backpack for the correct key.
ClickDetector.MouseClick:Connect(function(Player)
if Player.Backpack:FindFirstChild("Key") then
print("Access granted!")
else
print("Access denied!")
end
end)
I would also check the Player too, if the Player is holding the key then it won’t be found in the backpack so would’nt open the door
I don’t believe you can click a detector while holding a tool unless it doesn’t have a handle.
And just for future clarity, please don’t put a ‘bug’ tag on posts like this since this isn’t a bug in the system, it’s just an issue that you need to learn about.
If the tool doesn’t have a script (since it’s only a key) then click detector will still work (even with a handle) while tool is being held.
This doesn’t appear to be accurate.
While holding a tool, the only event fired is Tool.Activated and a few other addicted to the tool. Every click detector (expect the ones on a GUI) is disabled when you equip a tool.
local Key = --key location
local clickDetect = --clickDetector location
clickDetect.MouseClick:Connect(function(plr)
if plr then
local Bp = plr.Backpack
local Sg = plr.StarterGear
if Bp:FindFirstChild("ToolName") and Sg:FindFirstChild("ToolName") then
print("Key was found!")
end
end
end)
Sorry about that!! Still kind of learning about devforum
Yeah, my bad. I was tired last night when I tried it out in one of my games - I actually forgot to disable the script inside the key