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 » Scripting Helpers
Home Search
 

Re: Pressing a Button

Previous Thread :: Next Thread 
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 10:44 AM
Which event do I use if I want to run a function after a specific key is pressed?
Report Abuse
MidnightBuilder23 is not online. MidnightBuilder23
Joined: 20 Dec 2013
Total Posts: 759
23 Mar 2014 10:46 AM
KeyDown
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 10:46 AM
on your keyboard?

you want the KeyDown event then.
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 10:46 AM
Thanks
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 10:47 AM
you might want to look on the wiki, it's not as easy as you had on your other script.
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 10:51 AM
On my other script?
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 10:53 AM
sorry, I thought you were someone else. xD
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 11:19 AM
So the wiki isn't telling me that you can set the KeyDown to run only after a specific key (e.g. only if "q" was pressed). Is it possible? If so, how?
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
23 Mar 2014 11:20 AM
mouse.KeyDown:Connect(function(key)
if key == "q" then
--do stuff
end
end)
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 11:32 AM
function abilities()
if key == "q" then
local bodySpin = Instance.new("BodyAngularVelocity")
bodySpin.P = 200000
bodySpin.angularvelocity = Vector3.new(0,15,0)
bodySpin.maxTorque = Vector3.new(bodySpin.P,bodySpin.P,bodySpin.P)
bodySpin.Parent = torso

wait(5)

bodySpin.remove()
end
end
mouse.KeyDown:connect(abilities)

Error: Players.Player1.Backpack.Tool.Script:14: attempt to index global 'mouse' (a nil value)

Help?
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 11:35 AM
ill give an example

you might want to use a local script and put this in the player's backpack

local script --

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

player.KeyDown:connect(funtion(key)
if key == "q" then
print("you pressed e"
end
end)

that should be right.
Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 11:36 AM
ill give an example

you might want to use a local script and put this in the player's backpack

local script --

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

mouse.KeyDown:connect(funtion(key)
if key == "q" then
print("you pressed e")
end
end)

this should be the right one now...

Report Abuse
yurhomi10 is not online. yurhomi10
Joined: 10 Dec 2008
Total Posts: 13886
23 Mar 2014 11:37 AM
omggggg

local script --

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

mouse.KeyDown:connect(funtion(key)
if key == "q" then
print("you pressed q")
end
end)

THAT SHOULD BE RIGHT NOW... sorry
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 12:16 PM
lol
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
23 Mar 2014 12:23 PM
I like to keep it simple and the other method of using functions, while it works, just is hard for me to remember with the parentheses and stuff. This is how I do it (Must be in a local script):

mouse = game.Players.LocalPlayer:GetMouse()

function onKeyDown(key)
if key == "e" then
print("Player Has Pressed The E Button")
end
end

function onKeyUp(key)
print("Player Let Go Of The E Button")
end

mouse.KeyDown:connect(onKeyDown)
mouse.KeyUp:connect(onKeyUp)
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 01:11 PM
function abilities(key)
if key == "q" then
local bodySpin = Instance.new("BodyAngularVelocity")
bodySpin.P = 200000
bodySpin.angularvelocity = Vector3.new(0,15,0)
bodySpin.maxTorque = Vector3.new(bodySpin.P,bodySpin.P,bodySpin.P)
bodySpin.Parent = torso

wait(5)

bodySpin:remove()
end
end
mouse.KeyDown:connect(abilities)

So uh.... this still isn't working....Can someone help me find out whats wrong?
Report Abuse
VongolaXII is not online. VongolaXII
Joined: 12 Mar 2011
Total Posts: 127
23 Mar 2014 01:13 PM
The script has no errors, but nothing is happening either
Report Abuse
MidnightBuilder23 is not online. MidnightBuilder23
Joined: 20 Dec 2013
Total Posts: 759
23 Mar 2014 01:59 PM
if string.byte(key) == 113
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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