How do I loop through two folders?

Hello! I have a small issue with my code.

I have two folders.

lol

They contain models of plate and food.

I want to loop through these folders at the same time.

				local attribute = box:GetAttribute("InsideItem")
				local food = game.ReplicatedStorage.Items.Normal:GetChildren()
				local plate = game.ReplicatedStorage.Items.Plate:GetChildren()
				for _,v in pairs(food,plate) do
					if v.Name == attribute then
						print("item found!")
					end
				end

I tried something like this but the problem is that it’s only looping through the food folder.

Please help!

1 Like

you can either make a loop for each folder seperate OR you can combine the 2 tables like so:

local combinedFolders = {}
for i, v in food do
	table.insert(combinedFolders, v)
end
for i, v in plate do
	table.insert(combinedFolders, v)
end
2 Likes

I think you can also make the two tables a tuple and combine them like that

local combined = {unpack(food), unpack(plate)}
1 Like

Try using the Spawn() method.

there is absolutely no reason to use spawn here

Thank you so much! It was the exact thing I was looking for

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.