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
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.
Thank you very much! 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