I am attempting to write a code that if you don't press the "H" key for 5 seconds, your backgui will disappear. It's like an inventory is what I'm trying to make.
The code:
01 | local function onKeyDown( key ) |
02 | print ( "Key:" , H, " Code:" , string.byte(key)) |
03 | then |
04 | game.StarterGui:SetCoreGuiEnabled( "2" , false ) |
05 | wait( 0.1 ) |
06 | game.StarterGui:SetCoreGuiEnabled( "2" , true ) |
07 | wait( 5 ) |
08 | game.StarterGui:SetCoreGuiEnabled( "2" , false |
09 |
10 | end |
11 | mouse.KeyDown:connect(onKeyDown) |
01 | mouse.KeyDown:connect( function (key) |
02 | print ( "Key:" , key, " Code:" , string.byte(key)) |
03 | if key = = "h" then --check if the key pressed is h |
04 | game.StarterGui:SetCoreGuiEnabled( "2" , true ) |
05 | mouse.KeyUp:connect( function (key) -- when the key is released |
06 | wait( 5 ) |
07 | game.StarterGui:SetCoreGuiEnabled( "2" , false ) |
08 | end |
09 | end ) |
10 | end ) |
btw I didn't test just tell me if it doesn't work and Ill fix
Here is some key function scripts I have made. Use this.
01 | local tool = script.Parent |
02 | tool.Selected:connect( function (mouse) |
03 | mouse.KeyDown:connect( function (key) |
04 | if key = = "q" then |
05 | print ( "Switching to next weapon" ) |
06 | elseif key = = "e" then |
07 | print ( "Switching to previous weapon" ) |
08 | end |
09 | end ) |
10 | end ) |