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

Help me with tool welds breaking?

Asked by
coo1o 227 Moderation Voter
10 years ago

Whenever I make weld my tool together, the weld DOES hold but when I equip the tool again, miniature parts are scattered EVERYWHERE. I observed it a bit and the welds break when the tool is unequipped, not when it is re-equipped. Only one weld survives and that's the weld that's welded to the parent of all welds (i.e All of the tool's welds are welded to the Handle and the surviving weld is the weld welded to the Handle) If you can help me with this I'll be ever grateful.

In case you want the weld script I used, here it is:

function weld(p,wt)
    for i,v in pairs(p:GetChildren()) do
        if v:IsA("BasePart") then
            wtcf = wt.CFrame
            vcf = v.CFrame
            weld = Instance.new("Weld", wt)
            weld.Part0 = wt
            weld.Part1 = v
            weld.C0 = wtcf:inverse()
            weld.C1 = vcf:inverse()
            v.Anchored = false
        end
    end 
end

weld(script.Parent, script.Parent.Handle)
0
I am no weld expert, does the parent need to be defined to work? FromLegoUniverse 264 — 10y
1
Are you calling this function (weld) every time the tool is equipped? nate890 495 — 10y

1 answer

Log in to vote
5
Answered by
MrNicNac 855 Moderation Voter
10 years ago

Here's a more dynamic tool weld script that will recycle existing welds. It should keep a static memory count instead of losing track throughout the game. Basically it'll keep a clone of the original weld handy and re-weld the tool every time it's equipped. The old joints have a tendency to just break away.

local t = script.Parent
local h = t.Handle
local e = {}

for i,v in pairs(t:GetChildren()) do
    if v:IsA("BasePart") then
        local w = Instance.new("Weld", game.JointsService)
        w.C1 = v.CFrame:toObjectSpace(h.CFrame)
        w.Part0 = h
        w.Part1 = v
        table.insert(e, w:Clone())
    end
end

script.Parent.Equipped:connect(function()
    for i,v in pairs(e) do
        v:Clone().Parent = game.JointsService
    end
end)
0
It works, thanks! :D coo1o 227 — 10y
Ad

Answer this question