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: NumPlayers Question

Previous Thread :: Next Thread 
Dralian is not online. 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
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
07 Aug 2016 10:32 AM
#game.Players:GetPlayers() >>>>>> game.Players.NumPlayers
Report Abuse
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
07 Aug 2016 10:36 AM
It probably fires the function when the second player joins
Report Abuse
Dralian is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
07 Aug 2016 10:59 AM
^
possibly, how can I fix it though?
Report Abuse
Dralian is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
07 Aug 2016 11:07 AM
b1
Report Abuse
Dralian is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
07 Aug 2016 11:18 AM
b2
Report Abuse
Kodran is not online. 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 is not online. Dralian
Joined: 21 Mar 2013
Total Posts: 7624
07 Aug 2016 11:46 AM
Ahh, thanks bro, appreciate it.
Report Abuse
G0odby3 is not online. 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
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