New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How does for i,v in pairs work and how is it used?

Asked by 14 days ago

What does this mean.

for i,v in pairs(Shop.Droppers:GetChildren()) do
    v.Title.Text = v.Name
    v.Price.Text = "$"..ItemFolder[v.Name].PriceVal.Value
        frame = "Droppers"

1 answer

Log in to vote
Answered by
Nanomatics 1107 Moderation Voter
14 days ago

Basically using for i, v in pairs is iterating through everything within the '()' brackets that are used after 'pairs' which is an array of objects/values, etc...

In your case under 'Shop' there is an object called 'Droppers' that has objects as children, from the looks of it, it seems that they are TextButtons.

So when you do Shop.Droppers:GetChildren() it returns an array/table of all the objects that are children of the object 'Droppers'. We then iterate through each one of them.

Look at iterating as if you are singling out each child that is in that table, and doing something to it separately.

That being said 'i' becomes the index (number/location) of the child and 'v' becomes the actual child object.

More on this here.

I tried to explain it to the best of my ability, hope I helped. If you have any other questions please let me know


Answer this question