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

[ANSWERED] Why is GetChildren() returning with 0 children?

I'm in the middle of creating a system that exports a table of data from an array of StringValues, but for some reason it isn't running at all. I've done some tests, and it appears that the GetChildren() method always returns no children when I use it on the specific object. Here is my code:

local module={}
function module.getQueue()
	local t={} --initialize table
	for i=1,#script.Parent.Queue:GetChildren() do --begin loop. Always runs for 0 iterations
		table.insert(t,script.Parent.Queue[tostring(i)].Value) -add something to the table. This is never executed.
	end
	return t --export table
end
return module

Both the module and the Queue object are located within a folder, if that helps.

If you can help, please do! Thank you!

2 comments

0

Could you show the other script requiring the module and using the function?

0

@funyun Okay, I've added it, but it doesn't really matter because that part has no issue. The problem area is lines 4 to 6.

1 answer

Your loop seems bit wonky. This should work better:

local module={}
function module.getQueue()
	local children = script.Parent.Queue:GetChildren()
	local t={}

	for i=1, #children do
		table.insert(t, children[i].Value)
	end

	return t --export table
end
return module

2 comments

0

I made the adjustment and was able to detect that the loop wasn't the problem, it was the GetChildren() that appears to not be working.

0

GetChildren works fine, the way you access the parts seemed shady. The way you did it, made it seem that all the children were named as growing sequence of numbers.

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