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

Is this the way to use :GetChildren()?

Asked by 9 years ago

I barely use :GetChildren() so yeah...

x = script.Parent:GetChildren("script.Parent.Fire")
x.Enabled = false

---I dont get it....

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

:GetChildren() returns a table you can iterate through.

In the case you just attempted, you should use the FindFirstChild function, which returns a child with the specified name.

x = script.Parent:FindFirstChild("Fire")
x.Enabled = false

Here is a list of all functions that can be used on Instances.

To use :GetChildren(), most people do like so:

for index, value in pairs(script.Parent:GetChildren()) do 
    value:Destroy()
end

In the above script, GetChildren() returns a table the for loop can iterate through, then perform tasks for each one.

GetChildren is generally only used if you need to perform an object to several objects. Otherwise you can use FindFirstChild, or WaitForChild.

Ad

Answer this question