Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Index two tables within one in pairs loop?

I was wondering if it was possible to iterate though multiple tables within one loop for example:

local Tab = {"Test1","Test2"} local Tab2 = {"Test4","Test5"}

for _,v in pairs(Tab,Tab2) do print(v) end

It only prints the first indexed table? is this something that can be done? or do the tables need to be Iterated through separate loops?

2 comments

0

I’ve amended my answer a tad bit, please check it out!

0

You want it to print out "Test1" "Test4"? You could just print(v, Tab2[]). Remember that '' actually represents the index, although I have no idea if you were looking to do this or what the accepted answer does

1 answer

✓ Accepted answer

No, you cannot. Though you can nest another Loop for every traversed Element in table1. So for this example I’m going to singularly check for every Users UserId is the UserId special to theirs. (May not make entire sense, though the Code should enforce my example)

local UserIds = {74087102, 72209828}; local Users = game:GetService("Players"):GetPlayers
for i = 1,#UserIds do
   for j = 1,#Users do
      if (User[j].UserId == UserIds[i]) then
         print(User[i].Name.." Is here!")
      end
   end
end

Hope this helps! P.S: You can find a more significant use of this, and it will come in handy in certain scenarios!

1 comment

0

For this example it consists of both mine, and your UserId for comparison.

This discussion is preserved as it was. New answers, comments, and votes are closed.