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

How come this keydown function isnt working?

Asked by 8 years ago

I have a surface gui pop up and then shrinks when you press e. It works the first time when i press e. So say I press e the first time and the gui pops up and then when i press e again it goes away. Then when i press e again it appears, but when i press e again then it doesnt go away... Help me please

01mouse.KeyDown:connect(function(key)
02    if keyDeb == false then keyDeb = true
03        if key == "e" then
04            spawnScreen()
05        end
06    elseif keyDeb == true then keyDeb = false
07        wait(2)
08        closeScreen()
09    end
10end)

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

First off, mouse.KeyDown is deprecated. Roblox recommends us to usehttp://wiki.roblox.com/index.php?title=API:Class/ContextActionService or http://wiki.roblox.com/index.php?title=API:Class/UserInputService instead.

However, when I look at your script, I can not find anything wrong with it functionally in solo mode. So it must have been a variable mistake or a mistake on the closeScreen() function

In the script below, I modified your script so that it works with UserInputService and all of the needed variables (excluding the screen functions):

01local keyDeb = false
02function KeyPressed(input, gameProcessedOnGUI)
03    if input.UserInputType == Enum.UserInputType.Keyboard then
04        local KeyPress = input.KeyCode
05        if keyDeb == false and KeyPress == Enum.KeyCode.E then
06            keyDeb = true
07          spawnScreen()
08        elseif keyDeb == true then
09            keyDeb = false
10            wait(2)
11            closeScreen()
12        end
13    end
14end
15UserInput.InputBegan:Connect(KeyPressed)
0
I found the problem anyways. There was no such thing as onKeyDown. My mistake. Also thanks for the new way to do it. Im an old coding junkie so im not used to this new stuff yet. TickTockTheory 106 — 8y
Ad

Answer this question