playerlist

In my gamemode, i need one player to be chosen at random. but i cant figure out how to select him.
could someone help me?

[lua]local randomplayer = table.Random( player.GetAll( ) )[/lua]

function GM:think()

if class.NumPlayers( class_juggernaut ) < 1 then
	local randomguy = table.Random( player.GetAll( ) )  
	randomguy:SetClass( class_juggernaut )
	randomguy:Spawn()
end

end

thats what i have written.
shouldn’t someone at random be chosen to become the juggernaut if there is less than 1 in the juggernaut class?
or do a player need to die to switch?

[lua]if team.NumPlayers( class_juggernaut ) < 1 then
local randomguy = table.Random( player.GetAll( ) )
randomguy:SetTeam( class_juggernaut )
randomguy:Spawn( )
end[/lua]

but juggernaut is a class, not a team

will it still work?

No, I didn’t think you could set classes like that.

but does the player change team instantaneous or after that life/round?