Looping through frames not consistent

I’m trying too loop through 12 frames in one central frame but it doesnt seem to want to be working, and it only gets me the first frame in the explorer hierarchy, any ideas?

local function findNearestFrame()
		for index,slot in ipairs(List:GetChildren()) do
			if slot:IsA("Frame") then
				for i,potentialItem in ipairs(List:GetDescendants()) do
					for i,item in ipairs(Logs) do
						if potentialItem.Name == item and potentialItem:IsA("ImageLabel") then
							local equation = (itemLocation - slotLocation).Magnitude < 80
							if equation then
								print("An item is close to "..slot.Name)
							end
							for k in pairs(Logs) do
								Logs[k] = nil
							end
						end
					end
				end
			end
		end
	end

image

Perhaps change this line:

for i,potentialItem in ipairs(List:GetDescendants()) do

To:

for i,potentialItem in ipairs(slot:GetDescendants()) do

Since you’re first getting each child of List, and if it’s a frame, you’re then getting the descendants of List again, which is redundant, so I assume you meant to input the value from the previous loop.

Alright I tried that but now its only recognizing slot 4

What do you mean by recognise? It loops through all frames though, right?

Well Im not even sure because its only printing one frame though

No thats for a separate table though

Then what is supposed to be ‘Logs’? What about ‘Slots’ too?

So basically im making an inventory with a dragging system and right now I just need it to recognize which slot is closer so thats why Im looping through all of them

edit : Logs is something different and isnt important


image

Closer to the cursor, you mean?

No the problem Im having is that im trying to use the slots so im looping through them but its not getting every slot

Replace the ipairs of the for loop in which you looped through Logs, with pairs.

It changed which slot it targeted but it still doesnt recognize the other slots

local function findNearestFrame()
	local equation = (itemLocation - slotLocation).Magnitude
	
	for _,slot in pairs(List:GetChildren()) do
		if slot:IsA("Frame") then
			for _,item in pairs(slot:GetDescendants()) do
				if table.find(Logs, item.Name) and item:IsA("ImageLabel") and equation < 80 then
					print("An item is close to " .. slot.Name)
					for _,v in pairs(Logs) do
						Logs[v] = nil
					end
				end
			end
		end
	end
end

What about this?

Thanks for taking the time to try and help me let me try to see if that works

ipairs should be used with arrays, and pairs should be used with dictionaries.

Seems like your potential solution didnt work either, I dont know whats going on

I’ve tested it myself with no issues looping through the frames and getting slots printed, so I’m not sure what you’re expecting as an output.

I want it to output the frame that is closest to the item that the players is holding and it only works on the one that it spawns in when I pick up the item it seems

edit : I just needed to get the descendants of the main frame called list
@Sterpant Thanks for trying to help
@PhoenixRessusection Thanks for trying your best