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

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

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

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

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