Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do I check how many players there are in game? using scripts

Asked by 6 years ago

Title

Nothing much to describe

Answers/Comments are appreciated

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This is pretty easy, you get the children of players and then get the table size by putting a '#' for it

1function GetPlayers()
2    return #game.Players:GetPlayers()
3end
4 
5while wait(1) do
6    local Players = GetPlayers()
7end

If you have questions or I made a typo, just ask

(You can also count them, but this way is easier, if you want for example to only count players with a value inside them named 'InGame' you can do things like this)

01function GetPlayers()
02    local Players = {}
03    for i,v in pairs(game.Players:GetPlayers()) do
04        if v:FindFirstChild('InGame') and v:FindFirstChild('InGame').Value then
05            table.insert(Players, v)
06        end
07    end
08    return #Players
09end
10 
11while wait(1) do
12    local Players = GetPlayers()
13end
0
So if I add a table ( tab = {} ) should i add tab = {GetPlayers()}? mudathir2007 157 — 6y
0
Wdym, don't understand what you're trying to say? User#20388 0 — 6y
0
Nevermind but thanks mudathir2007 157 — 6y
0
np User#20388 0 — 6y
Ad

Answer this question