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

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

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

✓ Accepted answer

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

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