|
| 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 |
|
|
|
| 14 Oct 2014 08:54 PM |
if key == "g" then gui.Visible = true end --example |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 14 Oct 2014 09:26 PM |
| Thanks you guys, you're all really good this. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 14 Oct 2014 09:30 PM |
| key:lower()--its ALREADY lower........ |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2014 09:31 PM |
| @Mk, it needs to be a local script to use :GetMouse() so just use localplayer |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 14 Oct 2014 10:11 PM |
That video is 12 minutes long... too long to watch.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 15 Oct 2014 04:14 PM |
| Played the game and it works online too. Go to my profile its there. |
|
|
| Report Abuse |
|
|