|
| 09 Feb 2017 04:20 PM |
local contestants = {}
game.Players.ChildAdded:connect(function(player) table.insert(contestants, player) end)
game.Players.ChildRemoved:connect(function(player) table.remove(contestants, player) end
while true do print(#contestants) wait(10) end |
|
|
| Report Abuse |
|
|
| |
|
|
| 09 Feb 2017 04:21 PM |
what's the point of this anyway? game:GetService("Players"):GetPlayers() returns a table of all players currently in the server
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 09 Feb 2017 05:10 PM |
local playing = {}
game.Players.PlayerAdded:connect(function(player) playing[player] = true end)
game.Players.PlayerRemoving:connect(function(player) playing[player] = nil end)
while wait() do for k,v in next, playing do print(k) end end
|
|
|
| Report Abuse |
|
|
Yvnx
|
  |
| Joined: 21 May 2016 |
| Total Posts: 73 |
|
| |
|
|
| 09 Feb 2017 07:01 PM |
| that is not how a remove works, remove will get rid of the value at that index in an array, not the key with that value |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:05 PM |
| If the player objects are stored in the array, wouldn't the values just change to nil when the player leaves? |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:06 PM |
it's just a horrible method of doing it to begin with
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:14 PM |
| local players = ## function ################### print(player, " was added") table.insert(players, player) end function playerRemoved(player) print(player, " was removed") for ## i in ipairs(players) do if player ## players[i] then table.remove(players, i) end end end while wait(10) do print(#players) end |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:15 PM |
local players = {}
function playerAdded(player) print(player, " was added") table.insert(players, player) end function playerRemoved(player) print(player, " was removed") for _, i in ipairs(players) do if player == players[i] then table.remove(players, i) end end end
game.Players.PlayerAdded:connect(playerAdded) game.Players.PlayerRemoving:connect(playerRemoved)
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:16 PM |
if you want to be slightly more efficient
local contestants = {} local count = 0
game.Players.PlayerAdded:connect(function(player) contestants[ player ] = player count = count + 1 end)
game.Players.PlayerRemoving:connect(function(player) contestants[ player ] = nil count = count - 1 end |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:33 PM |
| if you want to be slightly more efficient local contestants = ####################################### local count = #contestants |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:33 PM |
if you want to be slightly more efficient
local contestants = game.Players:GetPlayers() local count = #contestants
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2017 07:36 PM |
| ik but other than that cuz you could just do local ## # ################ "Players" ) local gc = pl.GetChildren while wait(10) do print( #gc(pl) ) end |
|
|
| Report Abuse |
|
|