What does for i, v in pairs() and ipairs do

Hi guys can anyone of you guys explain to me what the pairs and ipairs does in a simple way

I need an example

Thanks for taking your time while reading this

so what it does is it loops through a thing.

Sounds complicated? i’ll dm you, ill teach you about it.

It kinda does sound complicated but I did hear its useful

its VERY VERY useful, sounded complicated to me too until i found out how it works, its not really that complicated, its more of a beginner thing

oh ok, I’ll try to understand it with all my might.

1 Like

pairs() is kinda unpredicatble, but ipairs() not.

Source: Something i remembered from a long time ago.

You dont need to know the difference, nowadays you dont really need them

1 Like

so one of the use scenarios can be to find out how many parts are in the workspace.

1 Like

so you mean ipairs() aren’t that useful anymore?

1 Like

no, you dont need them anymore, but they cause no harm when using

1 Like

I think I do understand what you mean but ok

1 Like

why dont you look it up? Why does this post exist?

1 Like

I did last night but I didn’t understand any of them

1 Like

for i,v in ipairs(workspace:GetDescendants) do print(v.Name)

i is the index,
v is the instance.

For everything it will find, it will print out its name

1 Like

What do you not understand?

It just loops through a dictionary or table, then it gives you an index and a value

1 Like

I understand some part of the script but I don’t know how to use v though

1 Like

we can DM, ill teach you @MGC_MAD5

ill explain it to you in the DM’s

1 Like

its not super easy to explain (atleast for me)

for i,v in ipairs(workspace:GetDescendants()) do
print(v.Name) -- prints the name of the instance
print(i) -- prints the number in order of the instances inside (1,2,3,4,etc)
end
-- v is the instance (Part,Model,etc)
1 Like

Ok
I’ll dm you when I can but not now