I'm currently working on a menu Gui, and I'm trying to make it to where upon pressing T, the Gui will drop down into view, and upon pressing it again, the Gui will slide back up.
So far, it works perfectly, however the only problem is, I'm unsure how to prevent players from spamming the T key and making the Gui not work correctly.
(Also, all of the waits I'm using was my attempt to provide a cooldown.) Here's my code:
local userInput = game:GetService("UserInputService") local background = game.Lighting.MenuBackground userInput.InputBegan:Connect(function(input, gameProcessed) wait(0.1) if input.KeyCode == Enum.KeyCode.T and background.Enabled == false then wait(0.1) script.Parent.FrameXY:TweenPosition(UDim2.new(0.1, 0.1, 0.3, 0.1), "Out", "Bounce", 0.6) wait(0.1) background.Enabled = true elseif input.KeyCode == Enum.KeyCode.T and background.Enabled == true then wait(0.1) script.Parent.FrameXY:TweenPosition(UDim2.new(0.1, 0, -0.4, 0), "Out", "Quad", 0.6) wait(0.1) background.Enabled = false end end)
Any help?
You could use a boolean variable - set it to true when the gui completes its animation and check for it when the user presses T.
EDIT: Something like this, maybe:
local userInput = game:GetService("UserInputService") local dropped = false local finishedAnim = true userInput.InputBegan:Connect(function(input, gameProcessed) if input.KeyCode == Enum.KeyCode.T and finishedAnim and not dropped then finishedAnim = false -- drop-down animation dropped = true finishedAnim = true elseif input.KeyCode == Enum.KeyCode.T and finishedAnim and dropped then finishedAnim = false -- going up dropped = false finishedAnim = true end end)