Lately I've been trying to weld tools with small parts. When first equip the tool everything is fine and in place but when unequipped small parts are scattered everywhere and most of the welds break(some of them are still in place though).
I'm using this script to do the welding:
function weld()
local parts,last = {}
local function scan(parent)
for _,v in pairs(parent:GetChildren()) do
if (v:IsA("BasePart")) then
if (last) then
local w = Instance.new("Weld")
w.Name = ("%s_Weld"):format(v.Name)
w.Part0,w.Part1 = last,v
w.C0 = last.CFrame:inverse()
w.C1 = v.CFrame:inverse()
w.Parent = last
end
last = v
table.insert(parts,v)
end
scan(v)
end
end
scan(script.Parent)
for _,v in pairs(parts) do
v.Anchored = false
end
end
weld()

1 comment
I'm not sure if there is a more 'formal' solution to this, but when the same was happening to me (welds breaking when moving models in and out of Workspace) I found that re-welding it each time you move it to the workspace does the trick.