Nenno
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 9208 |
|
|
| 11 Jan 2017 03:15 PM |
local p = game.Players:getChildren() local n = #p
while n >= 6 do (Stuff here for minigames) end |
|
|
| Report Abuse |
|
|
badfitz67
|
  |
| Joined: 03 Jun 2010 |
| Total Posts: 13165 |
|
|
| 11 Jan 2017 03:17 PM |
I think it should, but what I usually do is handle player stuff (enough players in server and such) in another script and then disable and undisable the main script based on if there's enough players
Walking the world is so empty you know. In the land of the beautiful, beauty is cold. |
|
|
| Report Abuse |
|
|
pidgey
|
  |
| Joined: 16 Jan 2008 |
| Total Posts: 2739 |
|
|
| 11 Jan 2017 03:19 PM |
| theres a property in players called numplayers, pretty self explanatory |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2017 03:23 PM |
| I think this would be a perfect time to choose using triggers, like events. |
|
|
| Report Abuse |
|
|
Nenno
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 9208 |
|
|
| 11 Jan 2017 03:27 PM |
So local n = game.Players.NumPlayers
While n and so on... |
|
|
| Report Abuse |
|
|
pidgey
|
  |
| Joined: 16 Jan 2008 |
| Total Posts: 2739 |
|
| |
|
Nenno
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 9208 |
|
|
| 11 Jan 2017 03:31 PM |
| Badfitz, I will consider that, thank you very much. |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 11 Jan 2017 03:56 PM |
Please note that this code won't work except if ran when there's already 6 players in the lobby and the amount of players never goes under 6.
I would suggest using the PlayerAdded event and an debounce variable to check if the game loop is running.
http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerAdded http://wiki.roblox.com/index.php?title=Debounce
Like such:
local gameRunning = false
game.Players.PlayerAdded:connect(function(player) if not gameRunning then gameRunning = true while game.Players.NumPlayers >= 6 do -- Minigame stuff end gameRunning = false end end)
But there's better but more complex ways to do this. |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 11 Jan 2017 04:05 PM |
Adding 'and game.Players.NumPlayers >= 6' to 'if not gameRunning then' like:
game.Players.PlayerAdded:connect(function(player) if not gameRunning and game.Players.NumPlayers >= 6 then gameRunning = true
Is debatable, not really necessary if code in the if is :
gameRunning = true while game.Players.NumPlayers >= 6 and gameRunning do -- Minigame stuff end gameRunning = false
But if things like
LoadModels()
Are added, then adding 'and game.Players.NumPlayers >= 6' is necessary:
local gameRunning = false
game.Players.PlayerAdded:connect(function(player) if not gameRunning and game.Players.NumPlayers >= 6 then gameRunning = true
LoadModels()
while game.Players.NumPlayers >= 6 and gameRunning do -- Minigame stuff end gameRunning = false end end) |
|
|
| Report Abuse |
|
|
Nenno
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 9208 |
|
|
| 17 Jan 2017 03:38 AM |
Sorry if I'm necrobumping, but can anyone explain the way this function works, if it was not named?
game.Players.PlayerAdded:connect(function(player) |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 17 Jan 2017 05:49 AM |
You can use the wiki to found that sort of things:
http://wiki.roblox.com/index.php?title=API:Class/Players/PlayerAdded
Just use the search feature in the top right |
|
|
| Report Abuse |
|
|