Countdown
Lesson 3 of 18 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
EasyAt the bottom of the script:
- Write
local function setStatus(text)that sets the Status label'sText. - Count down from
Settings.Intermissionto 1, a second apart, showingIntermission: 5,Intermission: 4and so on. - After the countdown, show
Get ready!
Press Play and watch the board, 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.