I need a script to open and close gui with keybind "T" pls
local UrGui = --Put in ur Gui game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if key == "t" then if UrGui.Enabled == true then UrGui.Enabled= false else UrGui.Enabled= true end end 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
local UIS = game:GetService("UserInputService") local Gui = script.Parent --// this event fires as soon as you use an input device like mouse,keyboard etc... UIS.InputBegan:connect(function(input) --//make sure we only listen to the keystrokes from a keyboard and ignore anythign else if(input.userInputType.Name == "Keyboard") then --// make the Key useable and easy to remember. local Key = input.KeyCode.Name --// Press T to disable Gui if(Key == "T") then Gui.Enabled = false end --// Press G to enable Gui if(Key == "G") then Gui.Enabled = true end end end) --[[ --// this is commented out as its not used but its here for reference. this fires as you stop using an input device UIS.InputEnded:connect(function(input) --// listen to only the keyboad if(input.userInputType.Name == "Keyboard") then --// pressT for Blah!... woot! if(input.KeyCode.Name == "T") then print("Blah!") end end end)]]
Hope this helps! :)
local UIS = game:GetService("UserInputService") local gui = script.Parent UIS.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then local keypressed = input.KeyCode if keypressed == "T" then gui.Enabled = true if keypressed == "F" then gui.Enabled = false end end end end)
Try that and see if it works.