Page 1 of 1
Number of active players in game
Posted: Tue Nov 04, 2014 7:59 pm
by jeroon
Is there a way to show the number of active players in game? I'm using #game.players atm, but I've noticed that when a player leaves, he stays in the game.players table, so I can't see if the players in there are really ingame (not sure if this is a bug). Anyone got a workaround?
Re: Number of active players in game
Posted: Tue Nov 04, 2014 8:06 pm
by JamesOFarrell
jeroon wrote:Is there a way to show the number of active players in game? I'm using #game.players atm, but I've noticed that when a player leaves, he stays in the game.players table, so I can't see if the players in there are really ingame (not sure if this is a bug). Anyone got a workaround?
Code: Select all
function getPlayerCount(players)
local playerCount = 0
for i,player in ipairs(players) do
if player.character ~= nil then
playerCount = playerCount + 1
end
end
return playerCount
end
Re: Number of active players in game
Posted: Thu Nov 06, 2014 12:08 pm
by jeroon
So i set up a MP game, player 2 joins, player 2 quits, and i run this in player 1's console:
Code: Select all
/c if game.players[2].character == nil then
game.players[1].print("i'm not here")
end
And it prints nothing, so the table game.players still holds the character of players that have quit.
Re: Number of active players in game
Posted: Thu Nov 06, 2014 12:22 pm
by drs9999