I've been making a GUI Menu. All the code is inside a localscript. My problem is that in my elseif statement, instead of having to click the GUI just once, I have to click it twice. I would like it to only have to be clicked once. I have tried using a regular if else statement in the past as well, and I thought an elseif statement would help it. But the same result came. I am also unsure how to insert a debounce and if this is relevant to having to double-click the menu to close it. Here is the code:
local gui, button, buttonm1 = Instance.new("ScreenGui"), Instance.new("TextButton"), Instance.new("TextButton") gui.Parent = script.Parent button.Parent = gui button.Position = UDim2.new(0, 3, 0, 3) button.Size = UDim2.new(0, 200, 0, 75) button.BackgroundColor3 = BrickColor.new(0, 0, 0).Color button.AutoButtonColor = false button.TextColor3 = BrickColor.White().Color button.BorderColor3 = BrickColor.White().Color button.BorderSizePixel = 3 button.Text = "Menu" button.Font = Enum.Font.ArialBold button.FontSize = Enum.FontSize.Size18 buttonm1.Parent = button buttonm1.Position = UDim2.new(0, 6, 0, 6) buttonm1.Size = UDim2.new(0, 388, 0, 63) buttonm1.BackgroundColor3 = BrickColor.new(0, 0, 0).Color buttonm1.TextColor3 = BrickColor.White().Color buttonm1.BorderColor3 = BrickColor.White().Color buttonm1.BorderSizePixel = 3 buttonm1.Text = "Run" buttonm1.Font = Enum.Font.ArialBold buttonm1.FontSize = Enum.FontSize.Size14 buttonm1.Visible = false buttonm1.BackgroundTransparency = 1 buttonm1.TextTransparency = 1 button.MouseButton1Down:connect(function() if button.Size == UDim2.new(0, 200, 0, 75) then button:TweenSize(UDim2.new(0, 400, 0, 150)) while button.TextTransparency < 1 do button.TextTransparency = button.TextTransparency + .05 wait() end wait(.3) buttonm1.Visible = true while buttonm1.BackgroundTransparency <= 1 do buttonm1.BackgroundTransparency = buttonm1.BackgroundTransparency - .05 buttonm1.TextTransparency = buttonm1.TextTransparency - .05 wait() end elseif button.Size == UDim2.new(0, 400, 0, 150) then while buttonm1.BackgroundTransparency < 1 do buttonm1.BackgroundTransparency = buttonm1.BackgroundTransparency + .05 buttonm1.TextTransparency = buttonm1.TextTransparency + .05 wait() end buttonm1.Visible = false button:TweenSize(UDim2.new(0, 200, 0, 75)) while button.TextTransparency > 0 do button.TextTransparency = button.TextTransparency - .05 wait() end end end)
Again, my essential problem is my pet peeve of having to click twice to close the menu. If there is any reason why it has to be clicked twice, I am unaware of it. I would also greatly appreciate an answer on if a debounce is necessary to execute the script more efficiently.