Menu
CoddyTech

Countdown

Lesson 3 of 20 in Coddy's Roblox Game: Disaster Survival course.

Before every round the board counts down: Intermission: 5, 4, 3, 2, 1. Two tools make that.

A function gives a job a name. Every message in this game goes through one:

local function setStatus(text)
	status.Text = text
end

setStatus("Hello")

A numeric for loop can count down: its third number is the step, and -1 goes down one at a time. task.wait(1) pauses the script for a second, so the loop takes one second per number:

for seconds = 3, 1, -1 do
	print(seconds)
	task.wait(1)
end
print("Go!")

This prints 3, 2 and 1 a second apart, then Go! The countdown's length comes from Settings.Intermission, so changing the setting changes the game.

challenge icon

Challenge

Easy

Count down on the board before the round.

  1. At the bottom, write local function setStatus(text) that sets status.Text.
  2. Count down from Settings.Intermission to 1, a second apart: setStatus("Intermission: " .. seconds).
  3. After the loop, show Get ready!

Press Play: the board counts Intermission: 5 down to 1, then says Get ready. Then Check.

Try it yourself

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

print("Rounds last " .. Settings.RoundLength .. " seconds")

-- Every player gets Wins on the leaderboard
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- The status board in the lobby
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.StatusBoard

local status = Instance.new("TextLabel")
status.Name = "Status"
status.Size = UDim2.fromScale(1, 1)
status.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
status.TextColor3 = Color3.fromRGB(255, 255, 255)
status.TextScaled = true
status.Text = "Welcome to Disaster Survival!"
status.Parent = gui

-- Lesson 3: Countdown goes here

All lessons in Roblox Game: Disaster Survival

Practice on your own: Roblox playground