Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
for _,v in pairs(Folder:GetChildren()) do
    --foo()
end

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

0
Worked like a charm. Thanks a bunch. EnderGamer358 79 — 5y
0
Don't use `next , Folder:GetChildren()`. Use `pairs(Folder:GetChildren())` instead. RayCurse 1518 — 5y
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. :) SummerEquinox 643 — 5y
0
They're almost the same. pairs returns next User#19524 175 — 5y
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. SummerEquinox 643 — 5y
Ad

Answer this question