generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Wait for certain KeyDown

Previous Thread :: Next Thread 
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:23 PM
I need to wait for a certain key to be pressed without using --

function keydown(key)
if key == "a" then
run()
end
end

-- I want to use something more like using the :Wait() function, such as --

(code to determine if A is pressed):Wait()

-- suggestions?

Report Abuse
Wrathsong is online. Wrathsong
Joined: 05 Jul 2012
Total Posts: 22393
11 Feb 2017 03:23 PM
UserInputService


Ever wanted to learn how to script? Check out my YouTube channel: youtube.com/austintheslayer Want to see me code in action? Follow me on twitch: twitch.tv/austinrblx
Report Abuse
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:24 PM
Example?
Report Abuse
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:27 PM
Would it be:

wait(IsKeyDown('a'))

or

IsKeyDown('a'):Wait()
Report Abuse
NickPresents1 is not online. NickPresents1
Joined: 17 Aug 2014
Total Posts: 78
11 Feb 2017 03:28 PM
Something like

Mouse.KeyDown:connect(function(Key)
if Key == "a" then
run()
end
end)

also if you're wondering about the Mouse: - Mouse = plr:GetMouse()
and plr would be - plr = game.Players.LocalPlayer
Report Abuse
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:29 PM
As stated I do not want to use a function, I want to use a :Wait()
Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
11 Feb 2017 03:29 PM
local key;
repeat
key = Mouse.KeyDown:wait()
until key == "a"


Report Abuse
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:32 PM
this looks correct, I will try it
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Feb 2017 03:32 PM
dont use keydown

also

repeat user_input_service.InputBegan:wait() until user_input_service:IsKeyDown(Enum.KeyCode.A)
Report Abuse
RoyalBobby202 is not online. RoyalBobby202
Joined: 16 Apr 2011
Total Posts: 458
11 Feb 2017 03:32 PM
Works! Thank you.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Feb 2017 03:33 PM
if you use keydown wont function online, deprecated, use my example, plus the wait is more exact
Report Abuse
Wrathsong is online. Wrathsong
Joined: 05 Jul 2012
Total Posts: 22393
11 Feb 2017 03:37 PM
use wunder's example


Ever wanted to learn how to script? Check out my YouTube channel: youtube.com/austintheslayer Want to see me code in action? Follow me on twitch: twitch.tv/austinrblx
Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
11 Feb 2017 03:37 PM
You sir are completely and utterly autistic.

KeyDown works online. The wait is LESS exact and that also might not detect it because RBX.Lua is slow and you're using IsKeyDown. Your method is also less efficient because you're calling a function every time they press a key whereas I'm only comparing a string value.

All in all, KeyDown is better in every way shape or form except that ROBLOX won't let you receive certain characters.


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Feb 2017 03:38 PM
mine has a more exact wait because it checks as soon as a key is pressed so it is more efficient
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Feb 2017 03:39 PM
plus it wont lag your scripts if you use multiples of them due to them constantly looping and using that function when they shouldnt be
Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
11 Feb 2017 03:42 PM
You're doing the exact same thing, but instead you're using InputBegan which actually is fired by both mouse and keyboard. You're also doing it in a less efficient manner. For all intents and purposes, Mouse.KeyDown is a better and cleaner method of doing it, the only downside is that you cannot attach it to numbers, and that ROBLOX doesn't like it.

www.youtube.com/watch?v=-NuONuafxwk


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image