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 9 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:

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)

2 answers

Log in to vote
0
Answered by 9 years ago
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

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

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)

Answer this question