✓ Accepted answer
The bare bones of a countdown timer conventionally consist of a 'for' loop running backwards.
gametime = script.Parent
totalsec = 600
for i = totalsec, 0, -1 do
gametime.Text = i
wait(1)
end
This will only display the amount of seconds left, though - not in MM:SS format.
MM:SS FORMAT:
05:30
NOT MM:SS FORMAT:
330
To do so requires the knowledge of the modulo operator (%). A modulo operation returns the remainder in a division operation.
Example:
11 / 5 = 10 r 1
11 % 5 = 1
So, how do you implement this knowledge into the countdown timer? By:
Assigning more variables (minutes and seconds)
Get the amount of minutes left
Get the amount of seconds left without breaching the 59-second boundary
Stick to the first script if you don't really understand the modulo operator for now.
MODULO OPERATION EXAMPLE
For five minutes, this example will print the time counting up.
totalsec = 300
for i = 0, totalsec do
local Min = math.floor( i / 60 )
local Sec = i % 60
if Min < 10 then
Min = ("0".. Min)
end
if Sec < 10 then
Sec= ("0".. Sec)
end
print(Min .. ":" .. Sec)
wait(1)
end