Can someone explain me the use of this for loop? Your answer will be highly appreciated!
✓ ANSWER ACCEPTED
Please explain for i, v in pairs() do?
2 answers
✓ Accepted answer
a for i,v in pairs() do loop is a type of for loop often used for looping through tables.
An example is:
local myTable = {"my","table",5}
for i,v in pairs(myTable) do
print(i,v)
end
The i,v is Index and Value, where the Index shows the number you're up to in the loop and the Value is the ValueType of what you're up to. Eg, if on the second go it would print out 2 table.
Another example:
local model = workspace.DoorModel
for i,v in pairs(model:GetDescendants()) do
v.Transparency = .5
end
This would change all the descendants of the DoorModel to have their transparency set to 0.5.
Here's a great post that relates to your question.
In the answers section, there are many examples provided that explain what pairs does, as well as ipairs and next.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Oh, got it!
-1. The iterator used doesn't make it a different type of loop.