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 + Vector3.new(50,50,0)
    end
    end
	end
	end
	end

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
end

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";
end

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

if (admindicationary[tostring(sender)] or specialadmindicationary[tostring(sender)]) then
    print("admin")
end

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

commands.tp = 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.

commands.tp = function(sender,targetPlr,blah,blah) is just assigning it a function.

commands.tp(sender,targetPlr,blah,blah) will actually run the function.

THANK YOU FOR ALL YOUR SUPPORT

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

plr.Chatted:Connect(function(msg)
local blah = msg:Split(" ")
local otherBlah = msg(prefix)
local targetPlayer1 = blah
local blah = blah
commands[otherBlah] (blah,otherBlah,targetPlayer1,blah)