Need help, I'm a begginer.

Basically I have two teams. Is there a way to make it so when a player joins the server they would get moved to the team with the least players straight away?

Thanks a lot!

[lua]function hi( ply )
if (team.NumPlayers(1) < team.NumPlayers(2)) then
ply:SetTeam(1)
elseif (team.NumPlayers(2) < team.NumPlayers(1)) then
ply:SetTeam(2)
end
end

hook.Add( “PlayerInitialSpawn”, “978857645768608678696”, hi )[/lua]

Something along those lines for a noob to understand

You could also use this
**[Team.BestAutoJoinTeam

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Team.BestAutoJoinTeam)**

that too

Thanks! And that would go into init.lua correct?

yeah, or shared.lua if you are using wakeboarder’s method

Mine can be used on server aswell. The example it gives
[lua]
function GM:PlayerInitialSpawn( ply )
self.BaseClass:PlayerInitialSpawn( ply )
ply:SetTeam ( team.BestAutoJoinTeam() )
end[/lua]

is used in init.lua

don’t call self.BaseClass:PlayerInitialSpawn()

it gives my gamemodes an error that stops the gamemode from loading.

Even if i do it on a gamemode with literally nothing in it