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
11 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:

01function weld(p,wt)
02    for i,v in pairs(p:GetChildren()) do
03        if v:IsA("BasePart") then
04            wtcf = wt.CFrame
05            vcf = v.CFrame
06            weld = Instance.new("Weld", wt)
07            weld.Part0 = wt
08            weld.Part1 = v
09            weld.C0 = wtcf:inverse()
10            weld.C1 = vcf:inverse()
11            v.Anchored = false
12        end
13    end
14end
15 
16weld(script.Parent, script.Parent.Handle)
0
I am no weld expert, does the parent need to be defined to work? FromLegoUniverse 264 — 11y
1
Are you calling this function (weld) every time the tool is equipped? nate890 495 — 11y

1 answer

Log in to vote
5
Answered by
MrNicNac 855 Moderation Voter
11 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.

01local t = script.Parent
02local h = t.Handle
03local e = {}
04 
05for i,v in pairs(t:GetChildren()) do
06    if v:IsA("BasePart") then
07        local w = Instance.new("Weld", game.JointsService)
08        w.C1 = v.CFrame:toObjectSpace(h.CFrame)
09        w.Part0 = h
10        w.Part1 = v
11        table.insert(e, w:Clone())
12    end
13end
14 
15script.Parent.Equipped:connect(function()
16    for i,v in pairs(e) do
17        v:Clone().Parent = game.JointsService
18    end
19end)
0
It works, thanks! :D coo1o 227 — 11y
Ad

Answer this question