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
if m < 10 then minutesDisplay = "0"..m else minutesDisplay = m end for s = seconds, 0, -1 do if seconds > 59 then s = 59 end if s < 10 then secondsDisplay = "0"..s else secondsDisplay = s end text.Text = minutesDisplay..":"..secondsDisplay wait(1) end
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.
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
local AcceptButtonName = "Accept"; -- the name of the accept button local DeclineName = "Decline" local Count = false local tim = tick() function AcceptedInvite() local AcceptedTime = tick() local Difference = (tim - AcceptedTime) return Difference end script.Parent[AcceptButtonName].Activated:Connect(function() Count = true end) script.Parent[DeclineName].Activated:Connect(function() Count = false end) while wait(1) do if Count == true then local Current = AcceptedInvite() print(Current) end end
local timerbutton = game.StarterGui.Button --make a button timerbutton.MouseButton1Click:Connect(function() for i = 1, 10, 1 do timerbutton.Text = i end end)