A round system
Structure of the Toolbox Round System: intermission loop, map selection from Storage, teleporting and cleanup.
Quick start
- Open the Toolbox, switch to Scripts and insert Round System.
- Storage › Maps contains four template baseplates: Red Map, Blue Map, Yellow Map and Purple Map.
- Replace or edit them with your own map models.
- Press Play.
The world's own baseplate acts as the lobby. After the intermission a random map is cloned from Storage and every player is teleported to it. When the round timer expires, players return to the lobby and the clone is destroyed.
Configuration
Parameters are value objects inside the Round System script.
| Value | Default | Description |
|---|---|---|
LobbyTime | 15 | Intermission length in seconds. |
RoundTime | 90 | Round length in seconds. |
MinPlayers | 1 | Minimum players required to start a round. |
LobbyPosition | 0, 4, 0 | Teleport target after a round. |
MapPosition | 0, 0, 400 | Position maps are moved to with MoveTo. |
MapsFolder | Maps | Path in Storage to the model holding the maps. Nested paths use /, for example Maps/Hard. |
The map name shown in announcements is the model's Name.
Implementation
Resolving the maps folder
local Storage = game:GetService("Storage")
local function mapList()
local folder = Storage
for name in string.gmatch(setting("MapsFolder", "Maps"), "[^/]+") do
if folder then
folder = folder:FindFirstChild(name)
end
end
if not folder then
return {}
end
return folder:GetChildren()
endCountdown
Countdowns use game:Message, which updates a persistent top bar instead of the full-screen announcement:
local function countdown(label, seconds)
for left = seconds, 1, -1 do
game:Message(label .. " " .. left)
task.wait(1)
end
game:Message("")
endRound loop
local chosen = maps[math.random(1, #maps)]
local map = chosen:Clone()
map:MoveTo(setting("MapPosition", Vector3.new(0, 0, 400)))
game:Announce("Round starting on " .. chosen.Name .. "!", 3)
sendAll(findSpawn(map) or mapPosition + Vector3.new(0, 4, 0))
countdown("Time left:", setting("RoundTime", 90))
game:Announce("Round over!", 3)
sendAll(setting("LobbyPosition", Vector3.new(0, 4, 0)))
map:Destroy()Clone() instantiates the map from Storage and leaves the original in place. Destroy() removes the clone and stops any scripts it started.
Map requirements
- Each map is a model directly inside the maps folder.
- A part named
Spawndirectly inside the map sets the teleport target. Without one, players are sent toMapPosition. - Scripts and NPCs inside a map start when the map is cloned.