Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Very simple question but I couldn't find the answer anywhere else?

I'm trying to make a For loop that loops once for each child inside a folder. Basically, I want a function that does one command to each child in the folder (AKA, telling each audio inside the folder to play), and I've seen people do this with For loops before. How would I achieve this?

1 answer

✓ Accepted answer
for _,v in pairs(Folder:GetChildren()) do
	--foo()
end

Inside this loop, v will represent each child of the folder separately.

5 comments

0

Worked like a charm. Thanks a bunch.

0

Don't use next , Folder:GetChildren(). Use pairs(Folder:GetChildren()) instead.

0

Fair enough, I am not too informed on the differences, would you be willing to help me understand it on Discord? I'd love to learn. :)

0

They're almost the same. pairs returns next

0

Yeah, Ray just explained it to me. OP, while they both have nearly the same outcome - pairs() is a helper function, and is better to use here. I have amended my initial post.

This discussion is preserved as it was. New answers, comments, and votes are closed.