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

What does the "i" in "i, v in pairs()" stand for? [closed]

Asked by 8 years ago

This question already has an answer here:

Meaning the "i" in for i, object in pairs() ?

i know that the "v" stands for the current object being targeted by the script at the time and the pairs() stands for the list of objects you want to sort through, but what purpose does "i" serve? what can it be used for?

for i, v in pairs(game.workspace.model:GetChildren()) do
if v.Name == "Part" then
v.Name = "ScriptAccessed"
wait(1)
end
end

Marked as Duplicate by User#5423 and shayner32

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

So basically, the "i" is just a variable and because you are iterating through a table, you are basically getting the "key" and "value" of each item if that makes sense.

You could put anything there! (for k, v in pairs etc.)

An example, would be:

for key, value in pairs(game.Players:GetPlayers()) do
    print(key)
    print(value)
end

OUTPUT: 1 and Player1

1 is the key, because it is the 1st item in the table and Player1 is the value or object it is referencing!

Hope that makes sense!

If it did, please "Accept answer" - if not, comment below and I'll try and help more!

1
thank you. ace12345678135 50 — 8y
Ad