Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Index two tables within one in pairs loop?

Asked by
Cyrakohl 108
5 years ago

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?

0
I’ve amended my answer a tad bit, please check it out! Ziffixture 6913 — 5y
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 Vulkarin 581 — 5y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

0
For this example it consists of both mine, and your UserId for comparison. Ziffixture 6913 — 5y
Ad

Answer this question