✓ Accepted answer
Here is some code I've created that may help:
I used a variable called "timeleft" to store how long the player has left
local timeleft = 10
local button = script.Parent
local gui = script.Parent.Parent.Frame
button.MouseButton1Click:Connect(function()
timeleft = 11
end)
while true do
timeleft = timeleft - 1
script.Parent.Text = tostring(timeleft)
wait(1)
end
The above code simply resets the timer every click. Since you want the GUI to become invisible when the timer hits 0, you can add an if statement:
local timeleft = 10
local button = script.Parent
local gui = script.Parent.Parent.Frame
button.MouseButton1Click:Connect(function()
timeleft = 11
end)
while true do
timeleft = timeleft - 1
if timeleft <= 0 then
timeleft = 0
gui.Visible = false
else
gui.Visible = true
end
script.Parent.Text = tostring(timeleft)
wait(1)
end
If this helped please accept. Feel free to comment if you need help.
2 comments
wat
Use a for loop that goes up to 10 and you wait(1) inside that loop. But before that you should have a variable named "isClicked" or something. Set it to true when clicked.