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

Why doesnt my tool weld script work?

Asked by 9 years ago

So I have my parts inside the tool, and named one engine (and another handle) but every time you take it out it works but once you un-equip and re-equip it breaks apart. Any help? Here is my script:

function Weld(x,y)
    local W = Instance.new("Weld")
    W.Part0 = x
    W.Part1 = y
    local CJ = CFrame.new(x.Position)
    local C0 = x.CFrame:inverse()*CJ
    local C1 = y.CFrame:inverse()*CJ
    W.C0 = C0
    W.C1 = C1
    W.Parent = x
end

function Get(A)
    if (A.className == "Part") or (A.className == "Seat") then
        Weld(script.Parent.Engine, A)
    else
        local C = A:GetChildren()
        for i=1, #C do
        Get(C[i])
        end
    end
end

function Finale()
    Get(script.Parent)
end

Finale()

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

From what I observed, changing the parent of a group of parts with interconnected welds tend to break them. So what I would do is use Equipped/Unequipped events.

Tool = script.Parent

Tool.Equipped:connect(function()
    Finale()
end)

Tool.Unequipped:connect(function()
    Finale()
end)

Place these anonymous functions below the Finale function, where it is defined.

Ad

Answer this question