GetChildren() For models with models inside

So I’m using a GetChildren() to get the children of a model to unanchor it but if i run the command it says model2 does not have an anchor property. It works but it errors on Model2 which is a model inside the model I’m trying to use get children. How can I make it so it just gets everything even the models inside the model? Here is my script:

local Parts = game.Workspace.Overloader1.Metal:GetChildren()
		for _,v in pairs(Parts) do
			coroutine.wrap(function()
				v.Anchored = false
			end)() 
		end
2 Likes

You can use :GetDescendants() then check if it’s a BasePart to prevent erroring

Expanding on from what @desinied said, check out this page on the Roblox Developer Hub - Instance | Roblox Creator Documentation

So do I replace the GetChildren with GetDescendants? I dont know much abot scripting

:GetChildren() will return all of the immediate children present in that container, whereas :GetDescendants() will return all of the children of all the children of the container and so forth, so it is up to you.

So if I had a part in another part, :GetDescendants() would loop through both those parts, but :GetChildren() would only run on the parent part (in the model).

2 Likes