|
| 02 Jul 2012 03:54 PM |
How do I check for a certain number number of players in a game?
Also on a side note, how do I prevent any new players from entering a server after that number is reached, so a server is locked from new players once the server is full, but doesn't ever unlock? |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 02 Jul 2012 04:00 PM |
I don't know about your extremely complicated side-note but math.floor(game.Workspace.DistributedGameTime)
is the number of players |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 04:01 PM |
| How is DistributedGameTime the amount of Players? I don't quite understand. |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 02 Jul 2012 04:04 PM |
| There's a proberty in the Players service called "NumPlayers" and "MaxPlayers". Their names desribe themselves. |
|
|
| Report Abuse |
|
|
| |
|
Parthax
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 6941 |
|
| |
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
|
| 02 Jul 2012 09:09 PM |
| Or you can be a non-conformist and use #game.Players:GetChildren(). Up to you. |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 09:23 PM |
@NVI
Instance.new("Part",game.Players) |
|
|
| Report Abuse |
|
|
belial52
|
  |
| Joined: 10 Oct 2009 |
| Total Posts: 8074 |
|
|
| 02 Jul 2012 09:25 PM |
@Popin, Okay.
#game.Players:GetPlayers() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 09:34 PM |
@belial
game.Players.Name = "\0" |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 02 Jul 2012 09:36 PM |
@popin,
#game:GetService"Players":GetPlayers() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 09:38 PM |
@Legend
*opens RobloxApp.exe, replaces "Players" to "\0", saves and closes, and all Roblox clients update as expected* |
|
|
| Report Abuse |
|
|
| |
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 02 Jul 2012 09:39 PM |
| That won't work once they release the filtering API. |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 09:40 PM |
| I was talking about replacing it on the production line so that all clients update without the Players service. |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 02 Jul 2012 09:40 PM |
| I don't think you're going to be able to do that. |
|
|
| Report Abuse |
|
|
| |
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 02 Jul 2012 11:40 PM |
a=game:getChildren() for i=1, #a do if a[i].className == "Players" then print(a[i].NumPlayers) break end end
? |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 11:43 PM |
I really think the NumPlayers property should be removed or deprecated. Does the Teams service have a NumTeams property? Does every instance have a NumChildren property? No.
We can already get that information through the GetPlayers method (#Game:GetService('Players'):GetPlayers()). |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 02 Jul 2012 11:44 PM |
^
Changing 'Players' in the assembly would successively change it's ClassName too :3 |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 11:44 PM |
@Julien
But it is much more efficient to check a property than to gather all the children into a table and check the number of them. |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 02 Jul 2012 11:44 PM |
or #game.NetworkServer:children()
can also get the sneaky people not in the players list stalking the chat. |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 02 Jul 2012 11:45 PM |
@my other post
That was meant to HatHelper... :s |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 02 Jul 2012 11:47 PM |
Luc599345, how about
local a=game:getChildren() for i=1, #a do local b=nil pcall(function() b=a[i].NumPlayers end) if b~=nil then print(b) end end
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2012 11:48 PM |
@kingkiller1000
If it's more efficient, as you say, then why don't we have a NumChildren property in every instance? |
|
|
| Report Abuse |
|
|