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.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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
    v.MouseButton1Click:Connect(function()
        frame = "Droppers"
        itemdesc(v.Name)

1 answer

Log in to vote
1
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

Ad

Answer this question