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
 

How do you call an function when a key is pressed?

Previous Thread :: Next Thread 
weeshoopdawhoop is not online. weeshoopdawhoop
Joined: 27 Mar 2012
Total Posts: 225
19 Mar 2015 03:31 PM
for example when I press the "E" key on the keyboard
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
19 Mar 2015 03:35 PM
function IHAVEBEENCALLEDYEAH ()
local MOUSEOFAWSOMETOWN = game.Players.LocalPlayer:GetMouse()
print("IHAVEBEENCALLEDYEAH!")
end

function KEYMASTEROFHISPANOLA (key)
if key == "e" then
IHAVEBEENCALLEDYEAH ()
end
end

MOUSEOFAWSOMETOWN.KeyDown:connect(KEYMASTEROFHISPANOLA)
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
19 Mar 2015 03:35 PM
Wait I messed up


local MOUSEOFAWSOMETOWN = game.Players.LocalPlayer:GetMouse()
function IHAVEBEENCALLEDYEAH ()
print("IHAVEBEENCALLEDYEAH!")
end

function KEYMASTEROFHISPANOLA (key)
if key == "e" then
IHAVEBEENCALLEDYEAH ()
end
end

MOUSEOFAWSOMETOWN.KeyDown:connect(KEYMASTEROFHISPANOLA)

there we go.
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
19 Mar 2015 03:35 PM
You're going to have to define the mouse:

local mouse = game.Players.LocalPlayer:GetMouse()

Then this old thing:

mouse.KeyDown:connect(function(key)
if key=="e" then --check if the key is 'e'
print("E has been pressed")
end
end)
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
19 Mar 2015 03:36 PM
mouse.KeyDown is deprecated.

Use "UserInputService" instead.
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
19 Mar 2015 03:37 PM
I'm not used to the new stuff, I've always used KeyDown
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
19 Mar 2015 03:38 PM
Well it's time to change.
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
19 Mar 2015 03:38 PM
D:
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
19 Mar 2015 03:38 PM
Never used it. Could you explain how?
Report Abuse
KLGA is not online. KLGA
Joined: 19 Apr 2014
Total Posts: 2571
19 Mar 2015 03:40 PM
http://wiki.roblox.com/index.php?title=Userinputservice
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
19 Mar 2015 03:40 PM
http://wiki.roblox.com/?title=API:Class/UserInputService
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
19 Mar 2015 03:41 PM
local User = game:GetService("UserInputService")


User.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.K then
print("K")
end
end)


I script -~ chimmihc
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