Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a timer start when a text button is pressed?

Asked by 4 years ago
Edited 4 years ago

I am making a game where when a frame pops up asking if you accept the challenge, a timer should start after you hit the button and end once you complete the challenge. Most of the timer scripts I find have the timer starting as soon as the server opens. How do I go about doing this?

The closest thing I've found to what I want to happen is:

local text = script.Parent

local seconds = 59

local minutes = 14

local secondsDisplay = ""

local minutesDisplay = ""

for m = minutes, 0, -1 do

01if m < 10 then
02 
03    minutesDisplay = "0"..m
04 
05else
06 
07    minutesDisplay = m
08 
09end
10 
11for s = seconds, 0, -1 do
12 
13    if seconds > 59 then
14 
15        s = 59
View all 33 lines...

end

The problem is that it starts as soon as the server opens and I need it to wait until the accept button is clicked.

0
I would go about using tick(), in my opinion maxpax2009 340 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

TICK()

Tick() provides the time in seconds that has passed since 1st of January of 1970. It actually provides quite a few uses.

In this case, we would want to get the time since the invitation got accepted

01local AcceptButtonName = "Accept"; -- the name of the accept button
02local DeclineName = "Decline"
03local Count = false
04 
05local tim = tick()
06 
07function AcceptedInvite()
08local AcceptedTime = tick()
09 
10    local Difference = (tim - AcceptedTime)
11 
12    return Difference
13end
14 
15script.Parent[AcceptButtonName].Activated:Connect(function()
View all 29 lines...
Ad
Log in to vote
-1
Answered by 4 years ago
1local timerbutton = game.StarterGui.Button --make a button
2 
3timerbutton.MouseButton1Click:Connect(function()
4for i = 1, 10, 1 do
5timerbutton.Text = i
6end
7end)

Answer this question