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

What does for i,v in pairs mean? What does return true mean?

What do these things mean? Also please give good example.

1 answer

✓ Accepted answer

For Loops:

for i,v in pairs(obj)

You might have seen something like that, the purpose is to loop through the components of a model or a list, returning the next step in the array

local Model = workspace.Model

for i, v in pairs(Model:GetChildren()) do
	print(i, v.Name)
end

i will give you a number, v will give you the child of the model... since we are using GetChildren()

returning is a way of giving back,

local item = false
local function doSomething()
	if item == false then
		return false
	else
		return true
	end
end
if doSomething() == false then
	print("returned false")
end

breaking or returning can end loops too.

2 comments

0

model is incorrect. referencing a model doesn't implicitly return the getchildren of it. it's just a list / dictionary

0

returning all the children yeah...

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