Need help with looping through a table

  1. What do you want to achieve?
    I have a whitelist of players in a table, and i want to loop through them on PlayerAdded to see if the players id matches the one in the table, after that clone a spell that is whitelisted for that specific player and parent it to their gui.

  2. What is the issue?
    Don’t know how to loop through a table properly.

  3. What solutions have you tried so far?
    Tried going through devforum to see if people had similar problems like me, and haven’t got anything

-- Portion of the spells whitelist:
local SpellWhitelist = {
	[12625702] = {"All"}
	[32581425] = {"All"};
	[64237575] = {"AdminSpells"}; 
	[4759789373] = {"AdminSpells"}; 
	[128046674] = {"AdminSpells"};
	[142828340] = {"All"}; 
}

--Loop that i pathetically tried using:
for index, ids in pairs(SpellWhitelist) do
   if index == player.UserId then
			
		for index2, spells in pairs(ids[index]) do
			local ExtraSpell = script.ExtraSpell
			
			if ExtraSpell then
				print(SpellWhitelist)
				ExtraSpell:Clone()
				--ExtraSpell.title.Text = ids[index2]
				ExtraSpell.Parent = SpellBook
			end
		end		
	end
end

What is content of the ‘ids’ table?

ids is the value of the first for i loop

Oh right I missed that.

So you’re doing a fetch of the key ‘player.UserId’ on the table { “All” }.

Is your expected result “All”?

If yes then, you don’t need tables as values of your ‘SpellWhiteList’. You can store strings.

Can you show me an example, or if possible use this table that i already set up?

I’m not sure what your expected result is, but what you can try is instead of ‘ids[index]’ which is a nil value, loop over ‘ids’ which is a table.

As i explained in my post, my expected result is to loop through that table, and if the id of the player matches the id in the table, it will give him the spells which his id is equal to.

-- Portion of the spells whitelist:
local SpellWhitelist = {
	[12625702] = {"All"}
	[32581425] = {"All"};
	[64237575] = {"AdminSpells"}; 
	[4759789373] = {"AdminSpells"}; 
	[128046674] = {"AdminSpells"};
	[142828340] = {"All"}; 
}

--Loop that i pathetically tried using:
for index, ids in pairs(SpellWhitelist) do
   if index == player.UserId then
			
		for index2, spells in pairs(ids) do
			local ExtraSpell = script.ExtraSpell
			
			if ExtraSpell then
				print(SpellWhitelist)
				ExtraSpell:Clone()
				--ExtraSpell.title.Text = ids[index2]
				ExtraSpell.Parent = SpellBook
			end
		end		
	end
end