In a game mode i want it to select player at random and change there class how do i do this?
local randomplayer = player.GetAll[math.random(1, #player.GetAll())] randomplayer:SetTeam(x)
– get a table containing all connected players
local players = player.GetAll( );
– pick a random index and get the player at that index
local random_player = players[ math.random( #players ) ];
That would be the more user friendly version yes.
Actually, your code has a mistake - ‘player.GetAll’ is a function and you’re trying to index it. To fix it, you need to add ‘( )’ after GetAll.
Whoops, I’m being distracted by the kids screaming outside and me playing online poker with a friend.
[lua]local randomplayer = table.Random(player.GetAll())[/lua]
The avatar works well.
Don’t use ‘table.Random’ for tables that have numeric keys - it’s much slower.
Not enough to truly affect anything, except perhaps in very large tables, but I suppose you are right. I’ll leave the post alone for future reference anyway.