choose random player to join team 2 on gamemode start

[lua]
function GM:Initialize( ply )
local Players = player.GetAll()
for i = 1, table.Count(Players) do
local ply = Players*
ply:SetTeam( 2 )
end
end
[/lua]

Apparently that code chooses everyone in the game according to the wiki, How would I make it choose one?

table.Random(Players) maybe

[ERROR] gamemodes/tele/gamemode/init.lua:41: ‘for’ limit must be a number

  1. unknown - gamemodes/tele/gamemode/init.lua:41
  2. unknown - lua/includes/modules/concommand.lua:69

[lua]
for i = 1, table.Random(Players) do
[/lua]

I don’t understand the error?

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

randomplayer:SetTeam( 2 )
[/LUA]

table.Random(Players) returns a random item from your table, in case of Players, it obviously isn’t a number, but a player.

ohhhh okay that makes more sense

[editline]2nd October 2013[/editline]

Thank you :slight_smile: