Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 answer

✓ Accepted answer

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 comment

1

thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.