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

How do I access the "anchored" function without having to call each particular part?

Asked by 3 years ago

this is my current script:


while true do print(script.Parent.Part1.Anchored) print(script.Parent.Humanoid.Health) wait(20) script.Parent.Part1.Anchored = false script.Parent.Part2.Anchored = false script.Parent.Part3.Anchored = false script.Parent.Humanoid.Health = 0 print(script.Parent.Humanoid.Health) end

I think to do what I want it to, I would have to use the GetChildren Function? I dont really understand it though.

Family Tree: https://gyazo.com/34cdfcb7cb3ac03c1279db43b35aeaa6

1 answer

Log in to vote
1
Answered by 3 years ago

GetChildren Explanation

GetChildren is a function of Instance that returns a table of Instances. You can loop through this to modify each child.

How to Use GetChildren

Using it is actually pretty simple when you figure it out. Look at my example below. It will do a for loop on the children and then check their class to make sure they are actually parts.

for i,v in pairs(script.Parent:GetChildren()) do
    if v:IsA("BasePart") then -- BaseParts are basically what you want to use when checking through different types of parts in order to achieve the same result
        v.Anchored = false
    end
end
Ad

Answer this question