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

What is this other version of in pairs?

Asked by
iiAceMo 50
4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad

Answer this question