I need a script to open and close gui with keybind "T" pls
01 | local UrGui = --Put in ur Gui |
02 |
03 | game.Players.LocalPlayer:GetMouse().KeyDown:connect( function (key) |
04 | if key = = "t" then |
05 | if UrGui.Enabled = = true then |
06 | UrGui.Enabled = false |
07 | else |
08 | UrGui.Enabled = true |
09 | end |
10 | end |
11 | end ) |
The above answer works but Roblox is doing away with Keydown, Keyup events connected to the mouse object.
A better way to Future proof this is to use the UserInputService
from within a Local script inside your Gui.
Example on how to use the UserInputService
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local Gui = script.Parent |
03 |
04 | --// this event fires as soon as you use an input device like mouse,keyboard etc... |
05 | UIS.InputBegan:connect( function (input) |
06 | --//make sure we only listen to the keystrokes from a keyboard and ignore anythign else |
07 | if (input.userInputType.Name = = "Keyboard" ) then |
08 | --// make the Key useable and easy to remember. |
09 | local Key = input.KeyCode.Name |
10 | --// Press T to disable Gui |
11 | if (Key = = "T" ) then |
12 | Gui.Enabled = false |
13 | end |
14 | --// Press G to enable Gui |
15 | if (Key = = "G" ) then |
Hope this helps! :)
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local gui = script.Parent |
03 |
04 | UIS.InputBegan:Connect( function (input) |
05 |
06 | if input.UserInputType = = Enum.UserInputType.Keyboard then |
07 | local keypressed = input.KeyCode |
08 |
09 | if keypressed = = "T" then |
10 | gui.Enabled = true |
11 | if keypressed = = "F" then |
12 | gui.Enabled = false |
13 | end |
14 | end |
15 | end |
16 | end ) |
Try that and see if it works.