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
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
Just use this
local NumPlayers = game.Players.NumPlayers
print (NumPlayers)
It's easier then you think :)
Thanks :P
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)
wrong. game does have a players property, you can see it under Workspace
Technically, it's a child of 'game.'
Er, I mean instance.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Please do your research! Looking up 'Players' on the wiki and scrolling through Properties would have given you the answer!
I did that,It didnt answer my question when i studied the wiki page and tried it.