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

Weld script not un-anchoring and welding parts?

Asked by 8 years ago

So I have a script which is MEANT to weld objects and unanchor them, but It doesn't work, and with no script analysis errors, I don't know why.

function weld()
    local parts,last = {}
    local function scan(parent)
        for _,v in pairs(parent:GetChildren()) do
            if (v:IsA("BasePart")) then
                if (last) then
                    local w = Instance.new("Weld")
                    w.Name = ("%s_Weld"):format(v.Name)
                    w.Part0,w.Part1 = last,v
                    w.C0 = last.CFrame:inverse()
                    w.Parent = last
                end
                last = v
                table.insert(parts,v)
            end
            scan(v)
        end
    end
    for _,v in pairs(parts) do
        v.Anchored = false
    end
end

weld()
script:Remove()

1 answer

Log in to vote
1
Answered by 8 years ago
function weld()
    local parts,last = {}
    local function scan(parent)
        for _,v in pairs(parent:GetChildren()) do
            if (v:IsA("BasePart")) then
                if (last) then
                    local w = Instance.new("Weld")
                    w.Name = ("%s_Weld"):format(v.Name)
                    w.Part0,w.Part1 = last,v
                    w.C0 = last.CFrame:inverse()
                    w.C1 = v.CFrame:inverse()
                    w.Parent = last
                end
                last = v
                table.insert(parts,v)
            end
            scan(v)
        end
    end
    scan(script.Parent)
    for _,v in pairs(parts) do
        v.Anchored = false
    end
end

weld()
script:Destroy()

HARD TO EXPLAIN THE PROBLEM

GOODBYE

Ad

Answer this question