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

I don't understand :IsKeyDown(keycode)?

Hi guys, I checked the wiki and it didn't give me much detail.. I want a Gui to pop up when the M key is pressed.

This is what I tried but to me it didn't make sense.

game:GetService("UserInputService"):IsKeyDown(109):connect(function()
	game.Players.LocalPlayer.PlayerGui.MenuGui.Frame.Visible = true
end)

Could someone please tell me

  1. If that code would work
  2. How to use :IsKeyDown() properly please?

Many Thanks, Fahmi

1 comment

0

You could answer point 1 by trying it yourself?

1 answer

✓ Accepted answer

IsKeyDown is only for checking the current state of the keyboard. It isn't an event, it's a method.

You should read the wiki article on UserInputService before you start trying things randomly. If you're confused on how to do things, you could try reading this blog post which covers being able to use your resources in order to help you make games more effectively.

You want to use the InputBegan event of UserInputService.


game:GetService("UserInputService").InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		gui.Visible = not gui.Visible
	end
end)

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