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:
local function onKeyDown( key ) print("Key:", H, " Code:", string.byte(key)) then game.StarterGui:SetCoreGuiEnabled("2", false) wait(0.1) game.StarterGui:SetCoreGuiEnabled("2", true) wait(5) game.StarterGui:SetCoreGuiEnabled("2", false end mouse.KeyDown:connect(onKeyDown)
mouse.KeyDown:connect(function(key) print("Key:", key, " Code:", string.byte(key)) if key=="h" then--check if the key pressed is h game.StarterGui:SetCoreGuiEnabled("2", true) mouse.KeyUp:connect(function(key)-- when the key is released wait(5) game.StarterGui:SetCoreGuiEnabled("2", false) end end) 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.
local tool = script.Parent tool.Selected:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "q" then print("Switching to next weapon") elseif key == "e" then print("Switching to previous weapon") end end) end)