Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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!

0
Could you show the other script requiring the module and using the function? funyun 958 — 8y
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. ChipioIndustries 454 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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

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. ChipioIndustries 454 — 8y
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. ZarsBranchkin 885 — 8y
Ad

Answer this question