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

What is this other version of in pairs?

I see some other people do something like

for i=1, #part do

end

what's the difference between the normal in pairs and this in pairs and what does this other version do

1 answer

✓ Accepted answer

for i = startFloat, endFloat, incrementFloat will count up or down depending on the number you tell it. They are useful for things like countdown scripts. The info via Roblox Developer hub says:

"The for—do loop lets you run a command or group of commands a set number of times. The basic syntax includes a control variable, a start value, an end value, and an optional increment value.

Beginning with the start value, the loop will count up or down each time it runs the code between do and end until it reaches the end value. For example, the following loop starts at 1 and counts up until 5, printing the value of count (the control variable) on each iteration." For more information go to the Roblox Developer Hub page.

The for i, v in pairs() loop loops through a table. This can be useful for doing things for serveral children in an instance. For example:

local childrenOfModel = workspace.MyModel:GetChildren()

for i, v in pairs(childrenOfModel) do
	v:Destroy()
end

The :GetChildren() function automatically returns a table. The i stands for the index and the v stands for the value of the child.

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