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

What is --for_, tp in pairs(taggedParts) do ?

Asked by 4 years ago
Edited 4 years ago

I am not sure what this means exactly and I am trying to figure out how it works to understand it. I only don't understand for_, tp in pairs(taggedParts) do

local collectionService = game:GetService("CollectionService")
local taggedParts = collectionService:GetTagged("steps")

for _, tp in pairs(taggedParts) do
    local tile = tp
    local db = true

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

taggedParts is a table containing all the tag parts.

The code you provided is a for loop that runs N times. N being the number of items in your table. Each time it runs, it gets the next item in taggedParts, starting with the first item. tp is the current part in the taggedParts list.

If you were to make the loop more 'english-like' it would mean:

for each tagged part in a list of tagged parts
    do whatever you want here.
    usually this is doing something to to the tagged part
end

You usually use this type of loop when you have a list of items and you want to do something to each item or items in that list.

Ad

Answer this question