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

"GetChildren" method not finding things in workspace?

Asked by 7 years ago

So basically I have a folder in the Work space full of stuff and I need to get the children so I can work on it much more faster. script I don't know if I made a grammar mistake or something it would be cool if someone helped :)

parts = game.Workspace.Shirts.GetChildren()
part.Parent = char
2
You should really consider opening your output and looking at errors. It saves us from answering trivial issues like this. User#6546 35 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You didn't call the function correctly. You indexed it, which is still calling it, but you need to reference the object again if you're doing it that way.

You have to think of object-based functions in roblox the same way you'd look at a table and it's contents.

example;

local Part = { --This is the object
    Size = Vector3.new(1,1,1); --These are the properties
    CFrame = CFrame.new(0,0,0);
    BrickColor = BrickColor.new("Really red");
    GetChildren = function(self) --This is an object-based function
        --code
    end
}

What you're doing is referencing the 'GetChildren' function by indexing it: workspace.Shirts.GetChildren()

Since you're doing it this way, the 'self' parameter shown in the example is never given. You have to provide it manually.

parts = workspace.Shirts.GetChildren(workspace.Shirts)


The most common way to call the function, is to "invoke it as a method" - as eLunate stated in the comments. To do this, you use a colon(:) to reference the function. This way, you don't need to manually provide the 'self' parameter.

parts = workspace.Shirts:GetChildren()
2
He did call it, he just didn't invoke it as a method. User#6546 35 — 7y
0
Oh..Foolish of me okay thanks! extremeyes 10 — 7y
Ad

Answer this question