I just want to make it that when you spawn, it checks which team has the least amount of people and puts you on that team. But the output always gives me this error and I have no clue what it means. "Player is not a valid member of DataModel". Can someone help me fix the code and explain this error? Heres the code:
local teams = game:GetService("Teams")
local bluepeeps = game.Teams.Blue:GetChildren()
local redpeeps = game.Teams.Red:GetChildren()
game.Player.PlayerAdded:connect(function(player)
if bluepeeps > redpeeps then
player.TeamColor = "Bright Red"
else
player.TeamColor = "Bright Blue"
end
end)
This is in an ordinary script in the Workspace just in case that means anything. I'm still new to scripting so I was expecting this to not work I jsut don't know what that error means. Don't even know what the "Datamodel" is.

2 comments
I just realized roblox already does this... brainfart. But can someone still explain what I did wrong and the error so at least I learned something from this? XD
Well, first of all, players don't get added to the teams themselves. You'll have to count each team with code then check it's number, etc..