Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How does one create a door using .KeyDown?

Asked by
Xduel 211 Moderation Voter
10 years ago

As an example, the one used in Darkness 2. When you are at a certain distance from the door, if you press a certain key on your keyboard, it will open(If pressed, again it closes, but I can do that part.) How do I go about making a door like this? All help appreciated, Thank You. ~ Xduel

2 answers

Log in to vote
1
Answered by 10 years ago

Use magnitude to see how far a player is from a certain object, like so

if (workspace.Player1.Torso.Position - workspace.Part.Position).magnitude > 20 then
    --then open door
end

that will check if the player is 20 studs away from the part named Part in workspace and then do the following code

Ad
Log in to vote
0
Answered by 10 years ago

ScriptingHelpers is not a request site but here is the basics of the code that will detect when the player presses e and then prints that the player has.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    if Key == "e" then
        print("User pressed e")
        -- enter code here
    end
end)

If you need more help here's the wiki page on taking keyboard input: http://wiki.roblox.com/index.php?title=Taking_keyboard_input

0
Yeah, that is the easy part, but how will you know when it's close to a door? Tesouro 407 — 10y
0
I consider the keyboard input taking the more difficult part, the answer below talks about magnitude. cainsuper3 15 — 10y

Answer this question