Is it possible to run a for loop like this?

I was wondering, is it possible to run a for loop like this?

local folder = workspace:WaitForChild('Folder1')
local replicatedFolder = game.ReplicatedStorage:WaitForChild('ReplicatedFolder')

for i, item in pairs(folder:GetChildren() and replicatedFolder:GetChildren()) do
       -- code here
end


When I try to do this the code that I am using seems to break and no errors appear in the output.

2 Likes

did you try to print “item” to see if something is there? also i would suggest to do something like this:

if item.Parent then
   print(item.Parent.Name)
end
2 Likes

The folders are not empty, I’ve looked in both folders when the game is running.

2 Likes

this is not about if the folders are empty, this is about to see when the loop breaks. by printing the items you could check if it loops all the way and by printing the parent you could check if it loop through both folders or only one folder

2 Likes

It doesn’t seem to loop through any of the items, it prints nothing.

1 Like

then try to take off one of the GetChildren() and try again to see if it works

1 Like

It does work if I remove it, I was wondering if it is possible to do this.

1 Like

Then my answer is: no, you cannot (not 100% sure though)

1 Like

Ok, I’ll make a function and then run two seperate for loops. I think that should work.

2 Likes

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