Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can i close gui with keybind "T" ?

Asked by 4 years ago

I need a script to open and close gui with keybind "T" pls

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
01local UrGui =    --Put in ur Gui
02 
03game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
04if key == "t" then
05if UrGui.Enabled == true then
06UrGui.Enabled= false
07else
08UrGui.Enabled= true
09end
10end
11end)
0
make sure it's local A_Mp5 222 — 4y
Ad
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

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

01local UIS = game:GetService("UserInputService")
02local Gui = script.Parent
03 
04--// this event fires as soon as you use an input device like mouse,keyboard etc...
05UIS.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
View all 30 lines...

Hope this helps! :)

Log in to vote
0
Answered by 4 years ago
01local UIS = game:GetService("UserInputService")
02local gui = script.Parent
03 
04UIS.InputBegan:Connect(function(input)
05 
06if 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
15end
16end)

Try that and see if it works.

0
Make sure its a local script inside of your GUI. wizz_zz 3 — 4y

Answer this question