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
mouse.KeyDown:connect(function(key) if keyDeb == false then keyDeb = true if key == "e" then spawnScreen() end elseif keyDeb == true then keyDeb = false wait(2) closeScreen() end 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):
local keyDeb = false function KeyPressed(input, gameProcessedOnGUI) if input.UserInputType == Enum.UserInputType.Keyboard then local KeyPress = input.KeyCode if keyDeb == false and KeyPress == Enum.KeyCode.E then keyDeb = true spawnScreen() elseif keyDeb == true then keyDeb = false wait(2) closeScreen() end end end UserInput.InputBegan:Connect(KeyPressed)