First you have to understand what a table is. Arrays and dictionaries are types of tables, arrays are like this,
local array = { "Hello", 1, true}
As you can see, an array is basically a variable, but it holds more than one value.
print( array[1] )
print( array[2] )
This would print “Hello”, because the first time we were telling it to print the first value in the table, and the second time it will print “1” because we’re telling it to print the second thing in the array.
In pairs takes a table, and goes through it. For example:
local array = { "Hello", 1, true}
for i, a in pairs(array) do
print(a)
end
a represents the value it is in middle of going through.
This would print in the output
Hello
1
true
i and a are just variables you can name them whatever you want.
this is very useful, let’s say you have a model, and you want to change every child of the model’s transparency to 0.5. instead of going through each part, you can just do this.
local children = game.Workpsace.Model:GetChildren()
for num, part in pairs(children) do
part.Transparency = 0.5
end
This works, because :GetChildren() returns a table with all the children of the model as the values.