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 » Scripting Helpers
Home Search
 

Re: For loop going twice?

Previous Thread :: Next Thread 
BornLeader1 is online. BornLeader1
Joined: 02 Jun 2011
Total Posts: 1795
05 Apr 2014 09:47 AM
for i,v in pairs(game.Players:GetChildren()) do
table.insert(Tbl_Players, v)
end

so basically, after it does that, and I print table I get -
Player1
Player2
Player1
Player2

and there is only 2 players in the game, no duplicates. This is the only thing that adds players to the table so what can I do?
Report Abuse
uyoyalt is not online. uyoyalt
Joined: 16 Apr 2013
Total Posts: 2860
05 Apr 2014 09:51 AM
I got that too, but I think mine is not a loop
Double printed.
Report Abuse
BornLeader1 is online. BornLeader1
Joined: 02 Jun 2011
Total Posts: 1795
05 Apr 2014 09:54 AM
I continue elsewhere to make values for each player in Tbl_Players and it makes two values for each player meaning that it probably wasn't double printed but actually made two for each.
Report Abuse
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
05 Apr 2014 09:56 AM
It runs through each player, but does what you want twice. I'd add a break after you do the table.insert.

When life gives you lemons... BURN HIS HOUSE DOWN! >:D
Report Abuse
BornLeader1 is online. BornLeader1
Joined: 02 Jun 2011
Total Posts: 1795
05 Apr 2014 10:04 AM
I got it to work somehow, I am not really sure how. Anyway, thanks for the tips and ideas.
Report Abuse
Ictis is not online. Ictis
Joined: 01 Sep 2011
Total Posts: 1216
05 Apr 2014 10:24 AM
My guess is you set it to run once for every player in the game. Two players = two outputs of the same data.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
05 Apr 2014 10:38 AM
for i,v in ipairs(game.Players:GetPlayers()) do
table.insert(Tbl_Players, v)
end


If that don't work, try;

do
for i,v in ipairs(game.Players:GetPlayers()) do
table.insert(Tbl_Players, v)
end
end


Although I don't think the second one would help
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
05 Apr 2014 10:41 AM
@warp, why is that do there? no point
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
05 Apr 2014 10:42 AM
I know right.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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