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

Key detection help?

Asked by 9 years ago

I've heard KeyDown has been removed from mouse, and I've been trying to find out how to detect When somewone has put down the wanted key:

Keydown = function(key)
      if key == Enum.KeyCode.F then

       end
end

this is how I think it is used ive used it sometimes but it sometimes errors. Can anyone help?

0
Look up UserInputService. They are using a new system that will support mobile devices and PC BobserLuck 367 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

No one uses or should use that way of scripting keyboard stuff, not sure if that's correct but I know what you mean.

Now, if you want to know what input the player is doing, we use UserInputService and it's pretty simple. Now to set up this, You should make a variable of the Service. Look bellow for the localscript and under that, information about it:

local UserInput = game:GetService("UserInputService")

UserInput.InputBegan:connect(function(Pressed)
    if Pressed.KeyCode == Enum.KeyCode.F then
        --Code
    end
end)

First, I used Pressed in the parameter, this just return what Input the player has done. Then we want to check if the given input is F, as you see here if Pressed.KeyCode == Enum.KeyCode.F then

Comment any questions, otherwise accept the answer!

Ad

Answer this question