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: local function onKeyDown

Previous Thread :: Next Thread 
Spinticorp is not online. Spinticorp
Joined: 05 Sep 2014
Total Posts: 77
14 Oct 2014 08:51 PM
How would I use this to make a GUI open when I press a key.
I got this off of the WIKI and I'm having a hard time trying to figure it out.

local function onKeyDown( key )
print("Key:", key, " Code:", string.byte(key))
end
mouse.KeyDown:connect(onKeyDown)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 08:54 PM
if key == "g" then
gui.Visible = true
end
--example
Report Abuse
Spinticorp is not online. Spinticorp
Joined: 05 Sep 2014
Total Posts: 77
14 Oct 2014 09:17 PM
That will work?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 09:19 PM
providing 'gui' is something like game.Players.LocalPlayer.PlayerGui.Gui.Label or something

also need to define 'mouse'

mouse = game.Players.LocalPlayer:GetMouse()
Report Abuse
Spinticorp is not online. Spinticorp
Joined: 05 Sep 2014
Total Posts: 77
14 Oct 2014 09:19 PM
so this?


local function onKeyDown( key )
if key == "g" then
game.Lighting.Backpack.Parent = game.StarterGui
end
end
mouse.KeyDown:connect(onKeyDown)
Report Abuse
Hunter4529 is not online. Hunter4529
Joined: 20 Oct 2013
Total Posts: 675
14 Oct 2014 09:23 PM
local function onKeyDown( key )
if key == "g" then
game.Lighting.Backpack.Parent = game.StarterGui
end
end
game.Players.LocalPlayer:GetMouse().KeyDown:connect(onKeyDown)
Report Abuse
ScriptGuilder is not online. ScriptGuilder
Joined: 07 Aug 2014
Total Posts: 848
14 Oct 2014 09:25 PM
assuming you have the gui in ServerStorage

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()


Mouse.KeyDown:connect(function(key)
if (key == 'p') then
a = game.ServerStorage.guiname:clone()
a.Parent = Player.PlayerGui
end.
end)

should be in a localscript inside starterpack
Report Abuse
Spinticorp is not online. Spinticorp
Joined: 05 Sep 2014
Total Posts: 77
14 Oct 2014 09:26 PM
Thanks you guys, you're all really good this.
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
14 Oct 2014 09:29 PM
^
Yes that will work but there are some flaws like do this.

Put this in a script and put it in StarterGui

This will work in studio and online

Player = script.Parent.Parent
mouse = Player:GetMouse()

function onKeyDown(key)
key = key:lower()
if key = "q" then
print("Ahh don't hurt me") -- Text that is printed
end

mouse.KeyDown:connect(onKeyDown)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 09:30 PM
key:lower()--its ALREADY lower........
Report Abuse
Hunter4529 is not online. Hunter4529
Joined: 20 Oct 2013
Total Posts: 675
14 Oct 2014 09:31 PM
@Mk, it needs to be a local script to use :GetMouse() so just use localplayer
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
14 Oct 2014 09:31 PM
^
MISTAKE ERROR ALERT

where it says "if key = "q" then

should be " if key == "q" then

sorry.

:(
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
14 Oct 2014 09:35 PM
@Hunter

It doesn't need to be in a local you just need to be able to locate the player.
Report Abuse
Hunter4529 is not online. Hunter4529
Joined: 20 Oct 2013
Total Posts: 675
14 Oct 2014 09:36 PM
This whole time i've thought you need to use a local script to do anything with the mouse o.o
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 09:37 PM
http://wiki.roblox.com/index.php?title=API:Class/Player/GetMouse

Notes
This item must be used in a LocalScript to work as expected online
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
14 Oct 2014 09:43 PM
^

Yes it has to be in a local script since GetMouse:() needs the player and Player = game.Players.LocalPlayer Anything with LocalPlayer needs a LocalScript
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 09:44 PM
O
M
G
just noticed:

'Following an update in July 2014, the mouse's icon can now be set with this method'

F_CK YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS FINNNNNAAALLLLLLYYY
lol, haven't went to wiki for a while xD
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
14 Oct 2014 10:09 PM
The video I made show that for GetMouse() It doesn't need to be local

https://www.youtube.com/watch?v=LUl8YYfsOiY&feature=youtu.be
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
14 Oct 2014 10:11 PM
That video is 12 minutes long... too long to watch.

-The [Guy]
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
14 Oct 2014 10:23 PM
"The video I made show that for GetMouse() It doesn't need to be local

https://www.youtube.com/watch?v=LUl8YYfsOiY&feature=youtu.be"

"to work as expected ONLINE"

ONLINE

in play solo, all scripts run on the client
Report Abuse
Mkhero4433 is not online. Mkhero4433
Joined: 28 Aug 2010
Total Posts: 227
15 Oct 2014 04:14 PM
Played the game and it works online too. Go to my profile its there.
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