|
| 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 |
|
|
|
| 22 Jan 2017 08:29 AM |
playeradded
if game.Players.NumPlayers >1 then start game end
This siggy is copyrighted © |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 22 Jan 2017 11:52 AM |
| Also don't do what serph said |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 22 Jan 2017 12:09 PM |
Change the else to an end and add this:
wait(5)
|
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 23 Jan 2017 12:10 AM |
^
@the why wouldn't you use the Players.NumPlayers property?
|
|
|
| Report Abuse |
|
|
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 |
|
|