Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help me with tool welds breaking?

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)

2 comments

0

I am no weld expert, does the parent need to be defined to work?

1

Are you calling this function (weld) every time the tool is equipped?

1 answer

✓ Accepted answer

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)

1 comment

0

It works, thanks! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.