|
| 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 |
|
|
| |
|
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 |
|
|
| |
|
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 |
|
|
| |
|
yurhomi10
|
  |
| Joined: 10 Dec 2008 |
| Total Posts: 13886 |
|
|
| 23 Mar 2014 10:53 AM |
| sorry, I thought you were someone else. xD |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 23 Mar 2014 01:13 PM |
| The script has no errors, but nothing is happening either |
|
|
| Report Abuse |
|
|
|
| 23 Mar 2014 01:59 PM |
| if string.byte(key) == 113 |
|
|
| Report Abuse |
|
|