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

Why doesnt my tool weld script work?

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

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.

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