How do I make a keybinded tool door?

In some games I’ve seen that they have made a door that you can open by pressing E, but only opens if you are holding a certain tool. I have also tried searching for it online but only found 2 results of what I was looking for, 1 was pretty much unconfigurable and the other was a misunderstanding.

In a nutshell, I need help with making a simple script that opens a door when you press E but only opens if you are holding the correct tool. Thanks :grinning:

here is an video from alvinblox about a keycard door: https://www.youtube.com/watch?v=AdOdkcrLLkA&t=127s i think it will kinda be the same

no, not really but thanks anyway. I am trying to make it so when you press E it opens. That video is for touch keycards

1 Like

You could make a localscript inside the tool which handles it like this flow:

  1. On Tool Equip, Connects a UserInputService function to check for E keybind press.
  2. In the keybind connection, you could check distance from character to the door, if its say less than 10 then you could Open/Close the door.
  3. On Tool Unequip, Disconnect the UserInputService Connection that you created before.
2 Likes

That could work, but I’m not the best scripter myself haha. Could you help me with this please? Thanks

You can use UserInputservice and there is a lot of others tutorials on YouTube…

The only tutorials on youtube are how to make a touch keycard door or how to make a keybinded door, I’m trying to combine the both and make a keycard keybind door.

I can’t really give you the total script for your needs, but as an example, I could show you what my flow would look like.

local tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local connection
local player = game.Players.LocalPlayer
local doorInstance = workspace.Door

local function Connect()
     connection = UserInputService.InputBegan:Connect(function(input, gp)
         if gp then return end

         if input.KeyCode == Enum.KeyCode.E then 
               if player:DistanceFromCharacter(doorInstance.Position) > 10 then return end
               --Stuff To Open/Close Door Here.
         end
     end)
end

local function Disconnect()
    connection:Disconnect()
end

tool.Equipped:Connect(Connect)
tool.Unequipped:Connect(Disconnect)

Also, this is just a really simple example, so i won’t say to copy this but it can be used to take an idea.

1 Like

Thank you very much! :smile: I configured it a little and it works perfectly. Don’t worry, I don’t just copy and paste I like to actually understand the functions of the script so I can use them in the future. Thanks again

1 Like