@InternallyAmplified GetChildren()
returns an array, not a table.
Edit: an array is a type of table.
In pairs is normally used for loops considering an objects children. A child is basically something that is under an object.
pairs
is basically a simplified function that tells the script what to do, pairs is almost the same as doing this:
function pairs(Table)
for i = 1, #Table do
return i, Table[i] -- "i" is the index while "Table[i]" is the object corresponding to the index
end
end
This is what pairs could be used for:
for i, v in pairs(workspace:GetDescendants()) do -- "i" is the "i" and "v" is the "Table[i]"
v.Name = i -- Makes the name of the object the index
end
Index is the numeric value of something: 1, 2, 3, 4, etc.
Replying to @xNick_O’s post below:
pretend I have a table:
local Table = {"a", "b", "c". "d"}
Then I do:
print(Table[4])
It will print "d"
.
I was just the index, so if I were to loop through that table with the index:
for i = 1, #Table do
print(Table[i]) -- prints "a", then "b", then "c", then "d"
end
The Number sign #
is just to tell how many things are in a table or array.