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

i,v in pairs question?

I see a lot of

for i,v in next

What does that do? I've never learned that?

3 answers

✓ Accepted answer

I'll give you a brief explanation of i pairs. Here's an example of an i pairs loop

for i, v in ipairs(game.Workspace:getChildren) do
	--//Gathers everything in workspace
end

the i = index You can change v to whatever you want.

There's 2 types of pairs. ipairs and pairs.

I prefer ipairs, because I've heard it's more effective. In reality, I'm not 100% sure.

Hopefully this helps!

(also, next might be a table, idk)

If you need further help then i,v in pairs is a loop, it brings each item in a certain folder, it can get everything in a table and is useful for indexing items, i would be a number or a key, v would be what the key holds,

for i, v in pairs(workspace:GetChildren()) do
	print(i,v)
end

This should print "1, Camera", "2, Terrain"

With keys you would be able to manipulate dictionaries:

local dict = {["Key"] = 50, ["MoreKeys"] = 100}
for i, v in pairs(dict) do
	print(i,v)
end

This should print "Key, 50"

Reasons to use this:

Maybe you want to find a certain part or value,

for i, v in pairs(workspace:GetChildren()) do
	if v.Name == "Desired part name" then
		print("Found part")
	end
end

Anywho, this is just if you needed further help.

1 comment

0

Even tho I’m not the one who asked this, TYSM for your help niel

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