Ad
Log in to vote
0

How do I make a GUI close after a set time?

Asked by 6 years ago

Ok so I've made a help script that automatically closes 10 seconds after you open it, and it works fine. But the problem I've been having is that if I closed it manually and then opened it manually while the script was waiting 10 seconds to close the gui, the time doesn't reset, so it closes when it would've closed if the player didn't interrupt the timer. What I'm trying to do is have the time reset whenever the GUI is opened. This is basically what the code looks like:

local HelpButton= script.Parent.Button
local HelpFrame = script.Parent.Frame
local HelpOpened = false
-------------------------------------------------------------------
HelpButton.MouseButton1Click:connect(function()
    if HelpOpened then
        HelpOpened = false
        HelpFrame.Visible = false
    else
        HelpOpened = true
        HelpFrame.Visible = true
        wait(10)
        if HelpOpened then
            HelpOpened = false
            HelpFrame.Visible = false
        end
    end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

This should work:

local HelpButton= script.Parent
local HelpFrame = script.Parent.Frame
-------------------------------------------------------------------
HelpButton.MouseButton1Click:connect(function()
    if HelpFrame.Visible then
        HelpFrame.Visible = false
    else
        HelpFrame.Visible = true
        wait(10)
        HelpFrame.Visible = false
    end
end)

Make sure to put this in the HelpButton!

0
But that doesn't reset the timer though TurboFusion 1821 — 6y
Ad

Answer this question