Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Key detection help?

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?

1 comment

0

Look up UserInputService. They are using a new system that will support mobile devices and PC

1 answer

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.