Hello, I am a beginner in scripting, and I was following a tutorial on making an obby. When I touch the button, it should make the gate open for 10 seconds (basically a timer):
However, I don’t understand what the purpose of “for _, button in pairs(buttons:GetChildren()) do”. Like, can’t I remove this line? Will the game work properly??
As @Inkthirsty mentioned removing the _ in the for loop would affect it as the button would now represent the index when the _ represents the index as it isnt really necessary and the button is the value which is a instance
_ is supposed to be the index of the child and button is the child itself.
You shouldn’t remove this for loop, as buttons is a folder containing parts, and you cannot connect Touched on a folder. You have to loop through every part and connect it there.
It was mentioned above but its important to understand that you can replace both “" and “v” with anything, so don’t feel the need to always name the index as ".” Also index can refer to different things based on the context of the loop. If you’re looping through a folder or array, index is essentially how far into the table / folder you’ve gotten. (1 to however long the folder is) And it can also be a name if you’re looping through a dictionary which is a table with named keys.
local Dictionary = {
["Key"] = ...,
Mine = ...,
}
local Array = {"Key", 1, 2}