RB-004
Roblox round timer script
A loop of waiting, intermission and round, with the time left shared in a StringValue.
- Script type
- Script
- Where it goes
- ServerScriptService
- Category
- Game flow
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Round timer: waiting for players -> intermission -> round -> repeat.
-- The time left is written to ReplicatedStorage.RoundStatus (a StringValue).
-- Show it with a GUI that reads that value.
local MIN_PLAYERS = 2
local INTERMISSION_SECONDS = 15
local ROUND_SECONDS = 60
local RESPAWN_AT_ROUND_START = true -- send everyone to the spawn when the round begins
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local status = ReplicatedStorage:FindFirstChild("RoundStatus")
if not status then
status = Instance.new("StringValue")
status.Name = "RoundStatus"
status.Parent = ReplicatedStorage
end
local function enoughPlayers()
return #Players:GetPlayers() >= MIN_PLAYERS
end
local function startRound()
-- Put your own round code here: pick a map, give weapons, teleport players...
if RESPAWN_AT_ROUND_START then
for _, player in Players:GetPlayers() do
task.spawn(function()
player:LoadCharacter()
end)
end
end
end
local function endRound()
-- Put your own end of round code here: show a winner, give rewards...
end
while true do
-- 1. Wait until enough players are in.
while not enoughPlayers() do
status.Value = "Waiting for players (need " .. MIN_PLAYERS .. ")"
task.wait(1)
end
-- 2. Intermission.
for secondsLeft = INTERMISSION_SECONDS, 1, -1 do
status.Value = "Next round in " .. secondsLeft
task.wait(1)
end
-- 3. The round.
if enoughPlayers() then
startRound()
for secondsLeft = ROUND_SECONDS, 1, -1 do
if not enoughPlayers() then
break
end
status.Value = "Round: " .. secondsLeft
task.wait(1)
end
endRound()
end
endHow to set it up
- Add the Script to ServerScriptService.
- To test alone, set MIN_PLAYERS to 1.
- Play. Select ReplicatedStorage > RoundStatus in the Explorer and watch the Value change.
- To show it on screen, add a TextLabel and a LocalScript that sets the text to RoundStatus.Value whenever RoundStatus.Changed fires.
Change it
- Put your game code in startRound and endRound.
- player:LoadCharacter() works because Players.CharacterAutoLoads is on by default. Set RESPAWN_AT_ROUND_START to false if you do not want everyone to respawn.
- The round ends early if too many players leave. Change that check if your game needs a winner first.
More in Game flow
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.