Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
|
| 07 Aug 2016 10:30 AM |
function countPlayers(player) repeat wait () until game.Players.NumPlayers >= 2 if game.Players.NumPlayers >= 2 then print("Enough players to begin") StartEvent:FireAllClients() else repeat wait () until game.Players.NumPlayers >= 2 end end
countPlayers()
function startRound() for i,v in pairs(game.Players:GetPlayers()) do v.TeamColor = game.Teams.Alive.TeamColor v.Character:MoveTo(workspace.AliveSpawn.Position) end end
startRound()
Since the number is '2', if 2 players join, it works fine. But if 3 join, only 2 get on the team. Not sure why, please help.
thx, appreciate it af. |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2016 10:32 AM |
| #game.Players:GetPlayers() >>>>>> game.Players.NumPlayers |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2016 10:36 AM |
| It probably fires the function when the second player joins |
|
|
| Report Abuse |
|
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
|
| 07 Aug 2016 10:59 AM |
^ possibly, how can I fix it though? |
|
|
| Report Abuse |
|
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
| |
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
| |
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 07 Aug 2016 11:34 AM |
Uhh dailyblarg is at it again...
NumPlayers will automatically update with the number of players in the server, GetChildren (or GetPlayers) on the other hand is a call to a function that actually has to find every child inside the instance, thus making it less efficient. This becomes event more relevant if you do something like this:
for i = 1, #game.Players:GetPlayers() do print(game.Players:GetPlayers()[i].Name) end
as if there are 5 players in the server that's 6 calls to that function rather than... 0.
Anyways, @op you shouldn't do repeat wait() until number > 2, you should just look when a player is added like
local startedGame = false
function startgame() startedGame = true --put everyone on the alive team end
game.Players.PlayerAdded:connect(function(p) if game.Players.NumPlayers >= 2 and not startedGame then startgame() end end)
Then when the game ends set startedGame to false and it will be able to run over and over again. |
|
|
| Report Abuse |
|
|
Dralian
|
  |
| Joined: 21 Mar 2013 |
| Total Posts: 7624 |
|
|
| 07 Aug 2016 11:46 AM |
| Ahh, thanks bro, appreciate it. |
|
|
| Report Abuse |
|
|
G0odby3
|
  |
| Joined: 26 Jan 2016 |
| Total Posts: 5587 |
|
|
| 07 Aug 2016 12:12 PM |
don't ever use numerical for loops on objects lmfaooo
it should've been
for i,v in next, game.Players:GetPlayers() do print(v.Name) end
- AbstractMadness, currently terminated. 0/1.5M+ :( |
|
|
| Report Abuse |
|
|