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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Key down...

Previous Thread :: Next Thread 
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 07:52 AM
So i have a script that when you press a certain key(e) that it should print something. But it keeps on saying in output that mouse is a nil value. Heres the script.

print("Ok you're good too go")

f=enabled
function onKeyDown(key)
key:lower()
if key == "e" then
if f ~= true then
return end
f = false
print("It worked!")


end
end
f=true
Mouse.KeyDown:connect(onKeyDown)
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
17 Jul 2014 08:03 AM
Define the mouse, an example would be:
Mouse = game.Players.LocalPlayer:GetMouse()
Assuming you're using a LocalScript.
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:30 AM
But im using a key wouldnt i have to define that not the mouse. Also its not a LocalScript. An example would be Im trying to make a note that when you press e a gui pops up and when you press e again it dissapears.
Report Abuse
BlupoV2 is not online. BlupoV2
Joined: 12 Nov 2012
Total Posts: 543
17 Jul 2014 08:33 AM
You can only use the KeyDown Event on Mouse.
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:34 AM
Alright, so why does it says mouse=nil in the output?
Report Abuse
BlupoV2 is not online. BlupoV2
Joined: 12 Nov 2012
Total Posts: 543
17 Jul 2014 08:36 AM
Did you define it?

i.e.

Mouse = [player]:GetMouse()

?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
17 Jul 2014 08:39 AM
Where is the script located?.
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:40 AM
Inside of a Model called Paper
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
17 Jul 2014 08:41 AM
Alternatively, you could use something like,
for i,v in pairs(game.Players:GetPlayers()) do
Mouse = v:GetMouse()
end
This would globally effect each player however you can just create a function and utilize an event to get the individual player if necessary.
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:45 AM
This will do just fine, Its a 1 player server game.
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:48 AM
Where would this fit into the script?
Report Abuse
18lpickett is not online. 18lpickett
Joined: 15 Jul 2012
Total Posts: 3121
17 Jul 2014 08:58 AM
B1
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
17 Jul 2014 09:08 AM
--Alright, you'll probably need to adjust this later however,
print("Ok you're good too go")
f=true
function onKeyDown(key)
key:lower()
if key == "e" then
if f ~= true then
return end
f = false
print("It worked!")
end
end
f=true

while wait() do
for i,v in pairs(game.Players:GetPlayers()) do
Mouse = v:GetMouse()
Mouse.KeyDown:connect(onKeyDown)
end
end

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