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: Wait for 2 Players

Previous Thread :: Next Thread 
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 07:54 AM
How do I scipt one of those systems to tell my game to wait until server Player count is = or > 2. If it is then begin game, but if any player joins during the round, he will not be affected until the current round is over?

Thank you,
Report Abuse
killerbot29003 is online. killerbot29003
Joined: 04 Oct 2014
Total Posts: 3054
22 Jan 2017 08:29 AM
playeradded

if game.Players.NumPlayers >1 then
start game
end


This siggy is copyrighted ©
Report Abuse
SeraphDemo is not online. SeraphDemo
Joined: 31 Oct 2016
Total Posts: 17
22 Jan 2017 08:32 AM
the 1st poster is semi-right, but not very informative
plus there's a much better way to do it that doesn't involve PlayerAdded
I'm assuming you have a game loop? inside that loop, put some checks
there's a useful proeprty called game.Players.NumPlayers
if at any point you need to pause and wait for >= 2 players:
repeat wait(.1) until game.Players.NumPlayers >= 2


Report Abuse
excellentAnarchy is not online. excellentAnarchy
Joined: 30 Dec 2008
Total Posts: 2557
22 Jan 2017 11:49 AM
If I decide to make a loop waiting for 2+ players then it will affecting the players in a loop, and the game will be starting over and over again, in a loop. How would I avoid this from happening?
Report Abuse
Thedagz is not online. Thedagz
Joined: 10 Mar 2012
Total Posts: 798
22 Jan 2017 11:51 AM
local Players = game.Players

local RequiredPlayers = 2

local GameStart = false

Players.PlayerAdded:Connect(function(Player)
local PlayerCount = Players:GetPlayers()
if not GameStart and #PlayerCount >= RequiredPlayers then
GameStart = true
-- more code
end
end)
Report Abuse
Thedagz is not online. Thedagz
Joined: 10 Mar 2012
Total Posts: 798
22 Jan 2017 11:52 AM
Also don't do what serph said
Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
22 Jan 2017 12:08 PM
Best way

while true do
contestants = {}
for _,player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
humanoid = player.Character:WaitForChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(contestants, player)
end
end
end
if #contestants >= 2 then
break
else
end
Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
22 Jan 2017 12:09 PM
Change the else to an end
and add this:

wait(5)
Report Abuse
SeraphDemo is not online. SeraphDemo
Joined: 31 Oct 2016
Total Posts: 17
22 Jan 2017 11:47 PM
"Also don't do what serph said"

what I said is the best way to do it, instead of creating a new variable (why?)
game.Players.NumPlayers does what you want automatically


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
23 Jan 2017 12:10 AM
^

@the why wouldn't you use the Players.NumPlayers property?


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
23 Jan 2017 12:12 AM
Kritikal you don't know how to script if you think that way is the best way. Jesus christ you're stupid.

OP here's a great and short way to do it:
local playersService = game:GetService("Players")
while playersService.NumPlayers < 2 do
playersService.PlayerAdded:wait() -- yield the thread until someone joins
end
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