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

function GetPlayers()
    return #game.Players:GetPlayers()
end

while wait(1) do
    local Players = GetPlayers()
end

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)

function GetPlayers()
    local Players = {}
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild('InGame') and v:FindFirstChild('InGame').Value then
            table.insert(Players, v)
        end
    end
    return #Players
end

while wait(1) do
    local Players = GetPlayers()
end
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