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

My backpack script isn't working. Can someone help fix it?

Asked by 11 years ago

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:

01local function onKeyDown( key )
02    print("Key:", H, " Code:", string.byte(key))
03then
04game.StarterGui:SetCoreGuiEnabled("2", false)
05wait(0.1)
06game.StarterGui:SetCoreGuiEnabled("2", true)
07wait(5)
08game.StarterGui:SetCoreGuiEnabled("2", false
09 
10end
11mouse.KeyDown:connect(onKeyDown)

2 answers

Log in to vote
0
Answered by 11 years ago
01mouse.KeyDown:connect(function(key)
02    print("Key:", key, " Code:", string.byte(key))
03if key=="h" then--check if the key pressed is h
04game.StarterGui:SetCoreGuiEnabled("2", true)
05mouse.KeyUp:connect(function(key)-- when the key is released
06wait(5)
07game.StarterGui:SetCoreGuiEnabled("2", false)
08end
09end)
10end)

btw I didn't test just tell me if it doesn't work and Ill fix

Ad
Log in to vote
-2
Answered by 11 years ago

Here is some key function scripts I have made. Use this.

01local tool = script.Parent
02tool.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)
10end)

Answer this question