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
01 | mouse.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 |
10 | end ) |
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):
01 | local keyDeb = false |
02 | function 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 |
14 | end |
15 | UserInput.InputBegan:Connect(KeyPressed) |