My script creates a team when an event is fired by a local script, but I can't figure out how to get a random color that isn't already used by other teams.

script.Parent.OnServerEvent:Connect(function(Player, Name)
 for i, v in pairs(game.Teams:GetChildren()) do	
 if Player.Team == game.Teams.Rogues then
  local filtered = game:GetService("Chat"):FilterStringForBroadcast(Name, Player)
  local Pack = Instance.new("Team")
   Pack.Parent = game.Teams
   Pack.Name = filtered
   Player.Team = Pack
   Pack.TeamColor = BrickColor.Random()
  local Info = Instance.new("StringValue")
   Info.Parent = Pack
   Info.Name = "Leader"
   Info.Value = Player.Name
   end
  end
end)

2 comments

0

create an array of possible colors and them remove a color from the array when a team chooses it. Therefore you will not get a color already taken because it will be removed from the array. Use table.remove()

0

Thanks so much!