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

unanchor all in group script not working?

Asked by 6 years ago

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

Log in to vote
-1
Answered by
xPolarium 1388 Moderation Voter
6 years ago

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)
0
Why are you using recursion and why didn't you use a local variable for unanchor? local function x(). CootKitty 311 — 6y
0
This is his same code with :GetDescendants() but I guess the realization is too hard. xPolarium 1388 — 6y
Ad

Answer this question