Round, Teams, and Win System for Roblox
Generate a robust round system for competitive, cooperative, or survival Roblox experiences. The result prioritizes server-side logic, predictable state transitions, and validation to prevent the client from controlling time, score, winner, or rewards.
The prompt guides the AI to adapt the code to the real hierarchy of your project: objects in the Explorer, Teams, SpawnLocations, RemoteEvents, and specific win rules. It is ideal for developers who need a ready-to-paste base for ServerScriptService, with comments, edge-case handling, and practical testing instructions.
The system can support intermission, minimum players, balanced distribution of participants across teams, countdowns, detection of alive players, victory by elimination or time limit, round cleanup, and automatic preparation for the next match.
Act as a senior Roblox developer specialized in Luau, client-server architecture, multiplayer security, and scalable round systems. Create a complete server Script for a round system with intermission, teams, timer, and victory condition, strictly adapted to the context of my game below. The main result must be exactly one **Script** (not a LocalScript and not a ModuleScript), made to be placed in **ServerScriptService**. It must contain all the authoritative match logic: round states, time countdown, team allocation, active player monitoring, win calculation, ending, cleanup, and preparation for the next round. Do not delegate gameplay decisions to the client. If my project already has RemoteEvents for UI, use them only to notify clients about state, time, and winner; never accept from the client information that defines damage, eliminations, team, currency, inventory, winner, or round end. Before writing the code, interpret and respect the context I will fill in. If any indispensable item is missing or ambiguous, ask at most 5 objective questions before generating the script. If there is enough information, do not ask questions and deliver the code directly. MY GAME CONTEXT (I will fill in): - Name of the main map Folder/Model and how to select a map: [PREENCHER] - Are there maps per round? Location of team spawns within the map: [PREENCHER] - Exact names of the Team objects in the Teams service: [PREENCHER] - Team allocation mode (balanced, random, preselected, etc.): [PREENCHER] - Minimum players to start: [PREENCHER] - Intermission duration in seconds: [PREENCHER] - Maximum round duration in seconds: [PREENCHER] - Win rule (last team standing, highest score, objective, tie on time, etc.): [PREENCHER] - Behavior when time runs out: [PREENCHER] - Players who join mid-match (spectator, next round, specific team): [PREENCHER] - Policy for a player who dies (eliminated, respawn as spectator, normal respawn, etc.): [PREENCHER] - Existing RemoteEvents/RemoteFunctions and their paths in the Explorer: [PREENCHER] - UI elements that should receive updates and expected data format: [PREENCHER] - Victory/participation rewards, if any: [PREENCHER] - Other scripts that this system must not duplicate or conflict with: [PREENCHER] Implement an explicit and readable state machine, preferably with states such as WAITING_FOR_PLAYERS, INTERMISSION, STARTING, IN_ROUND, and ROUND_ENDING. Use configuration variables at the top of the script for values that can be easily changed. The timer must be controlled exclusively by the server, decrease at consistent intervals, and never create multiple concurrent loops when players join, leave, or when a round ends. Make sure a new round only starts after the previous one has been fully finalized. Handle PlayerAdded, PlayerRemoving, and CharacterAdded correctly. When starting a round, determine a fixed list of eligible participants, distribute them among the teams according to the provided rule, load characters when necessary, and teleport each player using the configured SpawnLocation or BasePart, with checks for missing objects, characters without HumanoidRootPart, and characters still loading. Connect Humanoid.Died only for participants of the current round and disconnect/neutralize old connections to avoid leaks and deaths from previous rounds affecting the current round. The win condition must be recalculated on the server after deaths, player leaves, and relevant events. Handle edge cases: a player leaves when their team is the last alive, there are not enough players during intermission, everyone dies simultaneously, only one team has participants, matches tie, and players joining after the participant list is locked. Do not use indefinite waits; prefer task.wait, task.spawn, and state/unique round identifier checks to prevent stale routines. If I provide UI RemoteEvents, validate their existence with time-limited WaitForChild or defensive checks and send minimal data, for example: current state, seconds remaining, alive teams, and result message. Do not create RemoteEvents automatically without my authorization. Do not use DataStore, HTTPService, remote require, loadstring, or code dependent on plugins. Deliver your response in this structure: 1) brief summary of the assumptions adopted; 2) a section with the mandatory Explorer path: ServerScriptService > [suggested Script name]; 3) the full Luau code, ready to paste, inside a single markdown block ```lua, with useful comments and Luau typing when it increases safety/clarity; 4) objective instructions to configure the necessary objects and test in Roblox Studio with Test > Start Server and multiple Players. Do not deliver pseudocode, incomplete snippets, or hidden dependencies.