Use the Teams service to assign players to teams, show team colors, and build round-based gameplay with scores.
Most multiplayer games split into sides — red vs blue, survivors vs zombies, builders vs fighters. The Teams service handles assignment, scoring, and visual distinction so you don't have to build it from scratch.
live under the service. Create them in Studio or from a :
local Teams = game:GetService("Teams")
local red = Instance.new("Team")
red.Name = "Red"
red.TeamColor = BrickColor.new("Bright red")
red.Parent = Teams
local blue = Instance.new("Team")
blue.Name = "Blue"
blue.TeamColor = BrickColor.new("Bright blue")
blue.Parent = Teams
Each has a TeamColor — a BrickColor that colors the 's name in the leaderboard and their character's health bar. Two are the minimum for a match.
The property on a Team that sets its color in the leaderboard is .
Assign a to a with JoinTeam:
local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
-- alternate between red and blue
local teams = Teams:GetTeams()
local smaller = teams[1]
for _, team in ipairs(teams) do
if #team:GetPlayers() < #smaller:GetPlayers() then
smaller = team
end
end
player.Team = smaller
end)
The simpler approach: player.Team = red. The smarter approach: put them on whichever has fewer . Balanced keep games fair.
If AutoAssignable is true on a (the default), are assigned to automatically when they join. Set it to false if you want manual control.
Combine with to track scores:
Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local score = Instance.new("IntValue")
score.Name = "Score"
score.Value = 0
score.Parent = leaderstats
end)
end)
Score is per-, but you can sum all on a to get a score:
local function getTeamScore(team)
local total = 0
for _, player in ipairs(team:GetPlayers()) do
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats and leaderstats:FindFirstChild("Score") then
total += leaderstats.Score.Value
end
end
return total
end
How do you get all players currently on the Red team?
shine in round-based games. Here's a basic intermission :
local function pickTeams()
local allPlayers = Players:GetPlayers()
for i, player in ipairs(allPlayers) do
if i % 2 == 0 then
player.Team = red
else
player.Team = blue
end
end
end
while true do
task.wait(15) -- intermission
pickTeams()
-- start the round...
task.wait(120) -- round duration
-- announce winner based on team scores
end
The alternates between , runs the round, and repeats. You can add win , round counters, and -specific spawns on top of this skeleton.
Write a function that loops through all players and puts even-indexed players on the Red team and odd-indexed players on the Blue team.
local Players = game:GetService("Players")
-- assign players to teams by indexplayer.Team before awarding round rewards.Next: bug hunt — game systems.