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 i,v in pairs

Previous Thread :: Next Thread 
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 04:11 PM
What exactly does that mean? I've seen it in a few scripts, but i've never had to use it in a script that I've made. Could someone explain it to me?
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
07 Oct 2013 04:12 PM
It loops through a designated table.

v would be the value
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 04:13 PM
Okay, how/when would I need to use it in a script?
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 04:14 PM
http://wiki.roblox.com/index.php/Function_Dump/Core_Functions#pairs
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 04:16 PM
Alright, thanks. One more thing, could it be used for pairing up players in a game? Like for a 2v2 game?
Report Abuse
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
07 Oct 2013 04:17 PM
Oh yeah.

"U BROKE THE TV U IDIOT!" - CeaselessSoul
Report Abuse
9HB is not online. 9HB
Joined: 11 Dec 2012
Total Posts: 2461
07 Oct 2013 04:17 PM
Yes you could, that's an example of why you'd use it.

You'd loop through the 4 players you picked and assign them red or blue etc.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 04:19 PM
Okay, thanks for all the help guys.
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 04:31 PM
Actually, two more things, for the pairing up of the players, could I have more than two pairs? like "for i,v,x in pairs"? The second thing, how would I pair up the players with it? Like this?:
for i,v in pairs(game.Players:GetPlayers()) do
v.Teamcolor = Brickcolor.new("Bright red")
i.Teamcolor = Brickcolor.new("Bright yellow")
end
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 04:32 PM
v = the child(value)
i = a number
v.TeamColor = BrickColor.new("Bright red")
also, you only have 2, name it anything it doesnt ahve to be i,v
Report Abuse
9HB is not online. 9HB
Joined: 11 Dec 2012
Total Posts: 2461
07 Oct 2013 04:55 PM
Your code:

for i,v in pairs(game.Players:GetPlayers()) do
v.Teamcolor = Brickcolor.new("Bright red")
i.Teamcolor = Brickcolor.new("Bright yellow")
end


My code:


plrs = game.Players:GetChildren()

x = Brickcolor.new("Bright red")
y = Brickcolor.new("Bright yellow")

for i,v in pairs(plrs) do
if i = 1 or i = 3
v.Teamcolor = x
if i = 2 or i = 4
v.Teamcolor = y
else
end
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
07 Oct 2013 05:07 PM
Okay, I see how it works now.
Report Abuse
9HB is not online. 9HB
Joined: 11 Dec 2012
Total Posts: 2461
08 Oct 2013 02:06 AM
Don't even know if my code works, will only work for 4 ppl.
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