Tutorial · Game systems

How to make a countdown timer in Roblox Studio

Almost every round game shows a timer at the top of the screen: Intermission 0:15, then Round 2:00. The common way to build it is a server loop that changes a number every second. It works, but the timer jumps when the server is busy and the network carries an update every second forever. This guide uses a cleaner method: the server says once when the countdown ends, and every player's screen counts down to that moment on its own.

Updated 14 November 20267 min readBeginnerLuauWritten by

In short

In a Script in ServerScriptService, set two attributes on a Folder in ReplicatedStorage: Label (such as "Intermission") and EndsAt, which is workspace:GetServerTimeNow() + seconds. In a LocalScript in StarterGui, every frame work out EndsAt - workspace:GetServerTimeNow(), round it up and show it as m:ss. GetServerTimeNow gives the same clock on the server and on every client, so all players see the same time.

  • The server only sends one value per countdown, not one per second, and a player who joins halfway sees the right time at once.
  • The server still decides when the round really ends: it waits on its own clock, the client only displays.
  • Use math.ceil on the seconds left, so the timer shows 0:01 for the last second and 0:00 only at the end.

Get the script

Round countdown timer for every player

A server Script that runs intermission and round countdowns by publishing an end time and a label, which every player's timer counts down to in sync.

Script in ServerScriptService named Countdown
-- Script in ServerScriptService named Countdown.
-- Runs intermission and round countdowns. Clients show them from the EndsAt and Label attributes.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local INTERMISSION_SECONDS = 15
local ROUND_SECONDS = 120
local MIN_PLAYERS = 2 -- the round ends early when fewer are left in it

local countdown = Instance.new("Folder")
countdown.Name = "Countdown"
countdown.Parent = ReplicatedStorage

-- Shows a countdown on every screen and waits for it on the server.
-- stopEarly is checked four times a second; when it returns true the countdown ends at once.
local function runCountdown(label: string, seconds: number, stopEarly: (() -> boolean)?)
	local endsAt = workspace:GetServerTimeNow() + seconds
	countdown:SetAttribute("Label", label)
	countdown:SetAttribute("EndsAt", endsAt)
	countdown:SetAttribute("PausedLeft", nil)
	while workspace:GetServerTimeNow() < endsAt do
		if stopEarly and stopEarly() then
			break
		end
		task.wait(0.25)
		-- Paused (Step 3): hold here until another script resumes
		while countdown:GetAttribute("PausedLeft") ~= nil do
			task.wait(0.25)
		end
		-- Another script can add time by changing EndsAt (see "Add time" below)
		local current = countdown:GetAttribute("EndsAt")
		if type(current) == "number" then
			endsAt = current
		end
	end
	-- Show 0:00 on every screen, even if the countdown ended early
	countdown:SetAttribute("EndsAt", workspace:GetServerTimeNow())
end

-- Players taking part in the current round
local inRound: { Player } = {}

local function roundIsOver(): boolean
	-- Remove players who left or died, then check how many are left
	for i = #inRound, 1, -1 do
		local player = inRound[i]
		local character = player.Character
		local humanoid = character and character:FindFirstChildOfClass("Humanoid")
		if player.Parent ~= Players or not humanoid or humanoid.Health <= 0 then
			table.remove(inRound, i)
		end
	end
	return #inRound < MIN_PLAYERS
end

while true do
	-- Wait for enough players before counting anything
	if #Players:GetPlayers() < MIN_PLAYERS then
		countdown:SetAttribute("Label", "Waiting for players")
		countdown:SetAttribute("EndsAt", nil)
		repeat
			task.wait(1)
		until #Players:GetPlayers() >= MIN_PLAYERS
	end

	runCountdown("Intermission", INTERMISSION_SECONDS)

	-- Start the round: put your own code here (teleport players to the map, give tools...)
	inRound = Players:GetPlayers()

	runCountdown("Round", ROUND_SECONDS, roundIsOver)

	-- End the round: put your own code here (pick the winner, teleport everyone back...)
	countdown:SetAttribute("Label", if #inRound == 1 then inRound[1].DisplayName .. " wins!" else "Round over")
	task.wait(4)
end

RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts

Where to put it

Explorer: a server Script and a LocalScript
ServerScriptService
  Countdown Script new
ReplicatedStorage
  Countdown Folder (made by the script)
StarterGui
  TimerDisplay LocalScript new

Settings you can change

INTERMISSION_SECONDSIn the script
Length of the break between rounds. Default: 15.
ROUND_SECONDSIn the script
Length of each round. The server ends the round when it runs out, or earlier if the round is over. Default: 120.

The timer on screen is the TimerDisplay LocalScript (Step 2). Put your own round start and end code where the comments say in Step 1.

Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.

Prompt for RoCode

Add a round countdown timer to my game: a Script in ServerScriptService that loops a 15 second intermission and a 120 second round by setting a Label attribute and an EndsAt attribute of workspace:GetServerTimeNow() plus the seconds on a Countdown folder in ReplicatedStorage, ending the round early when fewer than 2 players are left, and a LocalScript timer at the top of the screen that counts down to EndsAt every frame as m:ss and turns red in the last 10 seconds.

On this page
  1. Get the script
  2. How it works
  3. 1. Server script
  4. 2. Timer GUI
  5. 3. Control it
  6. 4. Test
  7. Common errors
  8. With RoCode
  9. Questions
  10. Sources

How a synced countdown works

There are two ways to show the same timer to everyone:

Two ways to build a round timer
MethodHowDownsides
Tick every secondThe server sets TimeLeft to 60, 59, 58... in a loopOne update per second for the whole game. The timer jumps if the server lags. Fine for most games.
Send the end time (this guide)The server sets EndsAt once; clients subtract the current server timeYou need GetServerTimeNow, which takes one line. Pausing needs a second attribute.

The second method works because of workspace:GetServerTimeNow(). Roblox's reference describes it as the client's best estimate of the server's Unix time: every device gets about the same number at the same moment, whatever its own clock or time zone says, and the value never goes backwards. So if the server says "the round ends at 1794672000.5", every player can work out how long is left without asking again.

The round system guide uses the first method inside a complete round loop. Both are fine; this guide is for when you want a smooth timer, or a timer on its own.

Step 1: The server countdown

  1. Hover over ServerScriptService, click +, insert a Script and name it Countdown.
  2. Paste the code below. It makes the Countdown Folder in ReplicatedStorage itself.
Script in ServerScriptService named Countdown
-- Script in ServerScriptService named Countdown.
-- Runs intermission and round countdowns. Clients show them from the EndsAt and Label attributes.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local INTERMISSION_SECONDS = 15
local ROUND_SECONDS = 120
local MIN_PLAYERS = 2 -- the round ends early when fewer are left in it

local countdown = Instance.new("Folder")
countdown.Name = "Countdown"
countdown.Parent = ReplicatedStorage

-- Shows a countdown on every screen and waits for it on the server.
-- stopEarly is checked four times a second; when it returns true the countdown ends at once.
local function runCountdown(label: string, seconds: number, stopEarly: (() -> boolean)?)
	local endsAt = workspace:GetServerTimeNow() + seconds
	countdown:SetAttribute("Label", label)
	countdown:SetAttribute("EndsAt", endsAt)
	countdown:SetAttribute("PausedLeft", nil)
	while workspace:GetServerTimeNow() < endsAt do
		if stopEarly and stopEarly() then
			break
		end
		task.wait(0.25)
		-- Paused (Step 3): hold here until another script resumes
		while countdown:GetAttribute("PausedLeft") ~= nil do
			task.wait(0.25)
		end
		-- Another script can add time by changing EndsAt (see "Add time" below)
		local current = countdown:GetAttribute("EndsAt")
		if type(current) == "number" then
			endsAt = current
		end
	end
	-- Show 0:00 on every screen, even if the countdown ended early
	countdown:SetAttribute("EndsAt", workspace:GetServerTimeNow())
end

-- Players taking part in the current round
local inRound: { Player } = {}

local function roundIsOver(): boolean
	-- Remove players who left or died, then check how many are left
	for i = #inRound, 1, -1 do
		local player = inRound[i]
		local character = player.Character
		local humanoid = character and character:FindFirstChildOfClass("Humanoid")
		if player.Parent ~= Players or not humanoid or humanoid.Health <= 0 then
			table.remove(inRound, i)
		end
	end
	return #inRound < MIN_PLAYERS
end

while true do
	-- Wait for enough players before counting anything
	if #Players:GetPlayers() < MIN_PLAYERS then
		countdown:SetAttribute("Label", "Waiting for players")
		countdown:SetAttribute("EndsAt", nil)
		repeat
			task.wait(1)
		until #Players:GetPlayers() >= MIN_PLAYERS
	end

	runCountdown("Intermission", INTERMISSION_SECONDS)

	-- Start the round: put your own code here (teleport players to the map, give tools...)
	inRound = Players:GetPlayers()

	runCountdown("Round", ROUND_SECONDS, roundIsOver)

	-- End the round: put your own code here (pick the winner, teleport everyone back...)
	countdown:SetAttribute("Label", if #inRound == 1 then inRound[1].DisplayName .. " wins!" else "Round over")
	task.wait(4)
end

How the server part works

  • runCountdown sets the label and the end time, then waits on the server's own clock. The client never tells the server when time is up.
  • stopEarly is an optional function. During the round it is roundIsOver, which ends the round when fewer than MIN_PLAYERS are still alive and in the game.
  • The last line of runCountdown sets EndsAt to now, so every screen shows 0:00 straight away when the round ends early.
  • Waiting for players removes EndsAt, which the display shows as a label with no time.

Step 2: Show the timer on every screen

  1. Hover over StarterGui, click +, insert a LocalScript and name it TimerDisplay.
  2. Paste the code below and press Play.
LocalScript in StarterGui named TimerDisplay
-- LocalScript in StarterGui named TimerDisplay.
-- Counts down to the server's EndsAt attribute every frame, using the shared server clock.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local WARNING_SECONDS = 10 -- turn red for the last few seconds
local NORMAL_COLOR = Color3.new(1, 1, 1)
local WARNING_COLOR = Color3.fromRGB(255, 80, 80)

local countdown = ReplicatedStorage:WaitForChild("Countdown")

local gui = Instance.new("ScreenGui")
gui.Name = "TimerGui"
gui.ResetOnSpawn = false

local label = Instance.new("TextLabel")
label.AnchorPoint = Vector2.new(0.5, 0)
label.Position = UDim2.new(0.5, 0, 0, 12)
label.Size = UDim2.fromOffset(260, 44)
label.BackgroundColor3 = Color3.fromRGB(20, 20, 30)
label.BackgroundTransparency = 0.2
label.TextColor3 = NORMAL_COLOR
label.Font = Enum.Font.GothamBold
label.TextSize = 22
label.Parent = gui
Instance.new("UICorner").Parent = label

gui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")

local function formatTime(seconds: number): string
	return string.format("%d:%02d", seconds // 60, seconds % 60)
end

local lastText = ""

RunService.RenderStepped:Connect(function()
	local title = countdown:GetAttribute("Label")
	local endsAt = countdown:GetAttribute("EndsAt")
	local pausedLeft = countdown:GetAttribute("PausedLeft")
	local text = if type(title) == "string" then title else ""
	local secondsLeft: number? = nil

	if type(pausedLeft) == "number" then
		local left = math.ceil(pausedLeft)
		secondsLeft = left
		text ..= "  " .. formatTime(left) .. " (paused)"
	elseif type(endsAt) == "number" then
		-- The same clock the server uses, so every player sees the same number
		local left = math.max(0, math.ceil(endsAt - workspace:GetServerTimeNow()))
		secondsLeft = left
		text ..= "  " .. formatTime(left)
	end

	-- Only touch the label when the text changes, not 60 times a second
	if text ~= lastText then
		lastText = text
		label.Text = text
		label.TextColor3 = if secondsLeft and secondsLeft <= WARNING_SECONDS then WARNING_COLOR else NORMAL_COLOR
	end
end)

math.ceil rounds up, so with 0.4 seconds left the timer still shows 0:01, and 0:00 appears only when time is really up. seconds // 60 is whole minutes and %02d pads the seconds to two digits, so 65 seconds shows as 1:05. The script reads the attributes every frame, which is cheap, but only changes the label when the text changes.

A player who joins in the middle of a round gets the attributes as soon as the Folder loads, so their timer starts at the right number with no extra code.

Step 3: Add time, pause or end early

Because the countdown is just an attribute, other server scripts can change it. These snippets go in any server Script.

Add time

Push EndsAt later. The waiting loop in runCountdown re-reads EndsAt four times a second, so the round really lasts longer, and every screen jumps up by the same amount.

Script in ServerScriptService named AddTimeExample
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local countdown = ReplicatedStorage:WaitForChild("Countdown")

-- Give everyone 30 more seconds, for example when a bonus objective is captured
local function addTime(seconds: number)
	local endsAt = countdown:GetAttribute("EndsAt")
	if type(endsAt) == "number" then
		countdown:SetAttribute("EndsAt", endsAt + seconds)
	end
end

addTime(30)

Pause

A paused timer cannot use an end time, because the end keeps moving. The display already understands a PausedLeft attribute: while it is set, it shows that number and "(paused)". To pause, save how long is left; to resume, set a new end time from it. The loop in runCountdown also waits while PausedLeft is set, so the round really stops, not only the display.

Script in ServerScriptService named PauseExample
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local countdown = ReplicatedStorage:WaitForChild("Countdown")

local function pause()
	local endsAt = countdown:GetAttribute("EndsAt")
	if type(endsAt) == "number" then
		countdown:SetAttribute("PausedLeft", math.max(0, endsAt - workspace:GetServerTimeNow()))
	end
end

local function resume()
	local left = countdown:GetAttribute("PausedLeft")
	if type(left) == "number" then
		countdown:SetAttribute("EndsAt", workspace:GetServerTimeNow() + left)
		countdown:SetAttribute("PausedLeft", nil)
	end
end

pause()
task.wait(5)
resume()

End early

Pass a function as the third argument to runCountdown, as the round does with roundIsOver. It is checked four times a second; return true to stop. For example, end the intermission as soon as everyone pressed Ready, or a capture-the-flag round as soon as a team reaches 3 captures.

Step 4: Test it

  1. Open the Test tab, set Clients and Servers to 2 players and press Start. With one player in Play Solo the timer says "Waiting for players", because MIN_PLAYERS is 2. Set it to 1 to test alone.
  2. Both windows show "Intermission 0:15" counting down together, then "Round 2:00".
  3. In one window, reset the character during the round. With 2 players, the round ends at once, the timer drops to 0:00 and the other player is named the winner.
  4. In the last 10 seconds of a countdown the timer turns red.
  5. Lower ROUND_SECONDS to 20 while testing so you do not wait two minutes.

Common errors and fixes

Check the Output window first, in both the server and the client view.

The timer is blank

The Countdown Script sets the attributes. Make sure it is a Script in ServerScriptService and has no red error. "Waiting for players" with no time means fewer than MIN_PLAYERS are in the game.

The timer shows 0:00 but the round keeps going

Something changed EndsAt without the server loop. Only change it from server scripts, and only through the attribute, as in Step 3.

Infinite yield possible on WaitForChild("Countdown")

The server Script makes the Folder when it starts. If it is disabled or errors first, the LocalScript waits forever. See Infinite yield possible.

Players see slightly different times

Use workspace:GetServerTimeNow(), not os.time() or tick(). Those read each device's own clock, which can be off by seconds or minutes.

Build it with RoCode

If you would rather not wire the timer into your rounds by hand, RoCode can do it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the scripts in your Explorer.

You type

Add a round timer at the top of the screen: 15 second intermission, 2 minute rounds that end early when one player is left, red in the last 10 seconds, and 30 extra seconds when someone grabs the bonus orb.

RoCode does
  • Can read your place first to find your existing round code and hook the timer into it
  • Writes the scripts with Create Script and is told to compile-check each one with Check Script
  • Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time

How RoCode connects to Studio.

Questions

How do I make a countdown timer in Roblox Studio?

Have a server Script set an end time with workspace:GetServerTimeNow() + seconds as an attribute, and a LocalScript show endsAt - workspace:GetServerTimeNow() as minutes and seconds. Steps 1 and 2 have both scripts.

How do I make a timer that all players can see?

Put the timer's value on something replicated, like a Folder in ReplicatedStorage, from a server Script. Every client reads the same attribute and shows it.

Should a round timer run on the server or the client?

Both. The server decides when the round ends; the client only draws the time left. If the client decided, an exploiter could end rounds.

How do I format seconds as minutes and seconds in Roblox?

Use string.format("%d:%02d", seconds // 60, seconds % 60). 125 seconds becomes 2:05.

What is GetServerTimeNow in Roblox?

A Workspace method that returns the server's Unix time in seconds. On a client it is the client's best estimate of the server's clock, so all players get about the same value.

Sources and further reading

How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

Try RoCode on your own place.

Free every day, no card required. Install the plugin, describe the feature, and review what lands in Studio.