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

unanchor all in group script not working?

Hello. I recently found this script that let's you unanchor all of a group. I tried this, but it didn't work. Here is the script:

	function unanchore(obj)
for i,v in pairs(obj:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = false
end
unanchore(v)
end
end
unanchore(workspace.Building)
local a= Instance.new("Explosion")
	a.Parent = game.Workspace
	a.Position =Vector3.new( -140.07, 1.5, -133.87 )

1 answer

✓ Accepted answer

To unanchor everything inside of a model then you're going to want to use :GetDescendants() instead of :GetChildren().

What :GetDescendants() does is that it returns every child in the model so you can unanchor each one of those children if they're a part.

What :GetChildren() is doing is its returning only the children of the model you're looking for. What about the children inside those parts/models?

--Corrected unachore to unanchor because it bugs me.
function unanchor(obj)
	for i,v in pairs(obj:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
		end
		unanchor(v)
	end
end

unanchor(workspace.Building)

2 comments

0

Why are you using recursion and why didn't you use a local variable for unanchor? local function x().

0

This is his same code with :GetDescendants() but I guess the realization is too hard.

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