How to make a countdown timer

How do I make a countdown timer GUI?

1 Like

Hello!

Here is the simplest way of doing it:

local TIMER = 10 -- starting time

local textLabel = script.Parent -- path to your text label

local function CountDown()
	repeat
		textLabel.Text = TIMER -- change text every second
		wait(1)
		TIMER -= 1
	until TIMER <= 0
	textLabel.Text = ""
	--[[further code]]
end

Call this function when you need to start countdown.

There is one optional improvement. Use of tick() !

local RunService = game:GetService("RunService")

local TIMER = 10 -- starting time
local textLabel = script.Parent

-- A more precise way of waiting a second.
-- Superior wait() alternative!
local function TickSecond()
	local start = tick()
	repeat
		RunService.Heartbeat:Wait()
	until tick() - start >= 1
end

local function CountDown()
	repeat
		textLabel.Text = TIMER
		TickSecond() -- call above function each time
		TIMER -= 1
	until TIMER <= 0
	textLabel.Text = ""
	--[[further code]]
end
2 Likes

Adding to this you don’t need to make a new script entirely, in the script where the countdown begins just put his script into a coroutine wrap

coroutine .wrap(function()
-- Put Script
end)()
2 Likes