generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Would something like this work?

Previous Thread :: Next Thread 
Nenno is not online. 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 is not online. 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 is not online. 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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
11 Jan 2017 03:23 PM
I think this would be a perfect time to choose using triggers, like events.
Report Abuse
Nenno is not online. 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 is not online. pidgey
Joined: 16 Jan 2008
Total Posts: 2739
11 Jan 2017 03:28 PM
yup
Report Abuse
Nenno is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image