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

Getting Player Amount help?

Asked by
iLegitus 130
10 years ago

So ive tried :

local v = game.Players.Value 

Didnt work,Can anyone help? I'd just like to get the amount of players present at the current time. If you cant do that,Then inside a team could also help :P

0
Please do your research! Looking up 'Players' on the wiki and scrolling through Properties would have given you the answer! Perci1 4988 — 10y
0
I did that,It didnt answer my question when i studied the wiki page and tried it. iLegitus 130 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

Just use this

local NumPlayers = game.Players.NumPlayers
print (NumPlayers)

It's easier then you think :)

1
Thanks :P iLegitus 130 — 10y
Ad
Log in to vote
-1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

Of course local v = game.Players.Value wouldn't work. game.Players is not a Value Object, and game doesn't have a Players property. ;-;

One of two good ways (I recommend the second function, as it causes less activity in the game):

while wait(.25) do                  -- This will execute the code block every .25 seconds (continuous, spurring some activity in the game)
    local PlayersInGame = game.Players:GetChildren()        -- I believe you can use :GetPlayers() too?
    print(#PlayersInGame)
end

Or

game.Players.ChildAdded(function () -- This will execute the function every time a Player is added (won't be as continuous, therefore less activity)
    local PlayersInGame = game.Players:GetChildren()        -- :GetChildren() method will get everything in the Players instance. I believe you can use :GetPlayers() too?
    print(#PlayersInGame)       --Will print the amount of players in the instance
end)

EDIT

Apparently there's a "NumPlayer" property. Heheh. Didn't know that. ('._.)

print(game.Players.NumPlayers)
  

I'm keeping the other functions up for reference on how to find the number of objects in a given object. You can try and utilize the functions to self-update an object with a string value for display (such as the Text property for TextLabel)

E.g.

game.Players.ChildAdded(function ()
    local NumberOfPlayers = game.Players.NumPlayers
    script.Parent.TextLabel.Text = NumberOfPlayers .. " are in this game."
  end)
  
0
wrong. game does have a players property, you can see it under Workspace NinjoOnline 1146 — 10y
0
Technically, it's a child of 'game.' Redbullusa 1580 — 10y
0
Er, I mean instance. Redbullusa 1580 — 10y

Answer this question