So, I was working on a game which involves two teams: Red and Blue. I want to make it so that you will spawn in a random team, instead of Red all the time. Any script ideas would be really appreciated!
2 Likes
Enable AutoAssignable on both, it will automatically sort the people teams and let the teams as balance as possible
1 Like
game.Players.PlayerAdded:Connect(function(player)
player.Team = game:GetService("Teams"):GetChildren()[math.random(1, #game:GetService("Teams"):GetChildren())]
end)
2 Likes
local players = game:GetService("Players")
local teamService = game:GetService("Teams")
local teams = teamService:GetChildren()
players.PlayerAdded:Connect(function(player)
player.Team = teams[math.random(1, #teams)]
end)
Slight cleanup, when referencing something 2 or more times itβs best to declare a variable for it.
1 Like
Thanks for the additional info!