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: How do you make a for loop with multiple tables?

Previous Thread :: Next Thread 
jaghalkade is not online. jaghalkade
Joined: 29 Mar 2015
Total Posts: 96
30 Dec 2016 06:16 AM
For example:

model1 = workspace.model1:GetChildren()
model2 = workspace.model2:GetChildren()

Now how would use both of these in a for loop?


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
30 Dec 2016 06:17 AM
Just have 2 for loops?
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 06:17 AM
for _,part in next,model1 do
print(part.Name,"is a child of",part.Parent.Name)
end

for _,part in next,model2 do
print(part.Name,"is a child of",part.Parent.Name)
end



Report Abuse
jaghalkade is not online. jaghalkade
Joined: 29 Mar 2015
Total Posts: 96
30 Dec 2016 06:18 AM
#### Won't work since i use waits in the loops and they have to be ran at the same time
Report Abuse
jaghalkade is not online. jaghalkade
Joined: 29 Mar 2015
Total Posts: 96
30 Dec 2016 06:22 AM
ugh i hate these filters


Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Dec 2016 06:24 AM

spawn(function()
for _, v in pairs(model1) do
-- Do stuff
end
end)

for _, v in pairs(model2) do
-- Do Stuff
end



They'll be ran at the same time.
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 06:24 AM
function AffectModels(model1,model2)
for _,v in next,model1 do
print(v)
end
for _,v in next,model2 do
print(v)
end
wait() -- wait can go here
end

AffectModels(
workspace.model1:GetChildren(),
workspace.model2:GetChildren()
)


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 06:24 AM
You can use coroutines or spawning but I don't think you need to for your situation.


Report Abuse
jaghalkade is not online. jaghalkade
Joined: 29 Mar 2015
Total Posts: 96
30 Dec 2016 06:27 AM
ty


Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
30 Dec 2016 06:43 AM
function AffectModels(model1,model2)
for _,v in next,model1 do
print(v)
end
for _,v in next,model2 do
print(v)
end
wait() -- wait can go here
end

AffectModels(
workspace.model1:GetChildren(),
workspace.model2:GetChildren()
)


----------
this does not effect both tables at the same time still..
you really do need a co-routine or a single loop effecting both tables.

such would look like,

model1 = workspace.model1:GetChildren()
model2 = workspace.model2:GetChildren()

n = #model1
m = #model2
time = --set time

if n >= m then
for i = 0, m-1 do
model1[i] = --make change
model2[i] = --make change
wait(time)
end
for i = m to n-1 do
model1[i] = --make change
end
else
for i = 0, n-1 do
model1[i] = --make change
model2[i] = --make change
wait(time)
end
for i = n to m-1 do
model2[i] = --make change
end
end

.//. but you should probably just use a co-routine.
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
30 Dec 2016 06:44 AM
this is much simpler if the tables are a fixed length and the same length, but just in case it isnt ^^ that should work
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 06:48 AM
Prestigious, you missed the point of my approach, which was to make incremental assortments to the two tables.

If he's simply affecting the CFrame of each part in each model, both models are being affected in the same frame and then given a wait(), so you might as well not even piss with coroutines.

function Fly(model1,model2)
for _,v in next,model1 do
v.CFrame = v.CFrame*CFrame.new(0,.1,0)
end
for _,v in next,model2 do
v.CFrame = v.CFrame*CFrame.new(0,.1,0)
end
wait() -- each step will look like both are flying at the same time, because, well, they basically are.
end
Fly(workspace.model1:GetChildren(),workspace.model2:GetChildren())


Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
30 Dec 2016 06:58 AM
and you are calling the fly function in a loop right?

Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
30 Dec 2016 07:00 AM
ah ok i see now, we are moving models, i thought he wanted the wait time in between each child of the model, my bad
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 07:00 AM
Ya


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
30 Dec 2016 07:01 AM
*Ya to your first post
As for your second, I don't know. ¯\_(ツ)_/¯ OP didn't go that specific.
I just assumed if you're getting the children of a model and putting them in a loop that you're moving them.


Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
30 Dec 2016 07:01 AM
true that
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