How to make for loop through 2 tables [FIXED] [FIXED] [FIXED]

Really sorry if this is a bad question…

Hello! I would like to know how to know how to loop through 2 different tables.

Here is my wanted code I am making admin commands by the way:

	commands.fling = function(sender,targetPlr1, targetPlr2,command)
   for i, v in pairs(admins and specialAdmins) do
    if sender.UserId == v then
	if game.Players:FindFirstChild(targetPlr1) then
	game.Players:FindFirstChild(targetPlr1).Character.HumanoidRootPart.Position = 
game.Players:FindFirstChild(targetPlr1).Character.HumanoidRootPart.Position +,50,0)

And here is my tables:

local admins = {873724456}
local specialAdmins = {1624350571,873724456}

I tried the 2 table thing it did not work, well it gave an warning. I was thinking, maybe there is a proper way to do it.

I have already googled this.

PLEASE help I wish to make a ranking system, and this is required, because I use tables, if you have any help or an easier way to make my system, please do so!

1 Like

Where would you put the tables?

Please read the code, an example is in there. But you would use it this way:

for id1, id2 in zip(admins, specialAdmins) do
    -- do something

Ok… Let me test it… this topic might close

Simplest way is just to loop through them individually. If you really don’t want to always loop through them. You can try creating a dictionary with the valid IDs as follows:

local admins = {"873724456"}
local specialAdmins = {"1624350571", "873724456"}
local admindicationary = {};
local specialadmindicationary = {};
local sender = 873724456

for i = 1, #admins do
    admindicationary[admins[i]] = "admin";

for i = 1, #specialAdmins do --
    specialadmindicationary[specialAdmins[i]] = "specialadmin";

if (admindicationary[tostring(sender)] or specialadmindicationary[tostring(sender)]) then

All this does is prevent the constant looping for an admin check.

It would not be already running as it is stored into a table, right??? I have

local commands = {}

and = function(sender,targetPlr,blah,blah)

So it should not be running, right?? If I am wrong please tell me, I am new to coding.

The function will not run unless you put a () after the name. Or, if it’s connected as a listener. = function(sender,targetPlr,blah,blah) is just assigning it a function.,targetPlr,blah,blah) will actually run the function.


Open for easier loop table ideas

It’s actully working fine, so I am gonna close this topic now… I have tested it twice, 2 without admin 1 with special admin.

Because it actully has

local blah = msg:Split(" ")
local otherBlah = msg(prefix)
local targetPlayer1 = blah
local blah = blah
commands[otherBlah] (blah,otherBlah,targetPlayer1,blah)