I am trying to weld a multi-part sword together, but every Weld script I have found does not work with my sword, but it does with other tools (the one they came with).
Any help?
Weld Script 1
local previous local part = script.Parent:GetChildren() for i = 1, #part do if part[i].ClassName == "UnionOperation" or part[i].ClassName == "Part" then if not previous == nil then local weld = Instance.new("Weld") weld.Part0 = previous weld.Part1 = part[i] weld.C0 = previous.CFrame:inverse() weld.C1 = part[i].CFrame:inverse() weld.Parent = previous part[i].Anchored = false end previous = part[i] end end wait(3)
Weld Script 2
function Weld(a, b) local w = Instance.new("Weld") w.Part0 = a w.Part1 = b local CJ = CFrame.new(a.Position) local C0 = a.CFrame:inverse() * CJ local C1 = b.CFrame:inverse() * CJ w.C0 = C0 w.C1 = C1 w.Parent = a end function Get(A) if A.className == "Part" then Weld(script.Parent.Handle, A) A.Anchored = false else local C = A:GetChildren() for i=1, #C do Get(C[i]) end end end function Finale() Get(script.Parent) end script.Parent.Equipped:connect(Finale) script.Parent.Unequipped:connect(Finale) Finale()
I know they are quite large, but I have not found any errors in them. Any help is appreciated.
TheArmoredReaper
EDIT : I am trying to link this to a for loop, allowing the script to weld as many parts as needed. Every part inside my model is a Union, thus its class name is UnionOperation.
I just tried it myself and it kept the bricks relative position AND rotation as all the bricks had different rotations. First, anchor the bricks and put them where you want them and the rotation you want. Then shove this script in it.
local function weldBetween(a, b) --Make a new Weld and Parent it to a. local weld = Instance.new("ManualWeld", a) weld.Part0 = a weld.Part1 = b --Get the CFrame of b relative to a. weld.C0 = a.CFrame:inverse() * b.CFrame --Return the reference to the weld so that you can change it later. return weld end for i,v in pairs(script.Parent:GetChildren()) do if not(v.Name=="Handle") and not(v:IsA(script)) then weldBetween(script.Parent.Handle, v) v.Anchored=false end end script.Parent.Handle.Anchored=false
If you are trying to find a script then why not use plugins.It works great and effecting.Search up welding/welder or auto-weld. Thats just tips other than that I can't figure this script out. BTW when getting all children you have to name every part the same thing as the part you want to get.
Alright if you wish to weld two parts together by their relative position then i recommend this
Inside a Script:
local weld = function(a, b) local w = Instance.new("ManualWeld") w.Part0 = a w.Part1 = b w.C0 = CFrame.new() w.C1 = a.CFrame:toObjectSpace(b.CFrame) return w end local Tool = script.Parent -- get tool local Handle = Tool.Handle for i, part in pairs(Tool:GetChildren()) do if part:IsA("BasePart") then if part.Name ~= "Handle" then weld(Handle, part) end end end