I'm currently trying to weld a gun with a lot of parts. The only problem is that the gun model doesn't have each part's frontsurface facing forward so when the weld is put together, everything is messed up to look forward and it totally ruins the gun.
local function weld(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 = b.CFrame:inverse() * a.CFrame
--Return the reference to the weld so that you can change it later.
return weld
end
local function weldBetween(...)
local parts = {...} -- A list of all the arguments passed to this function
local rootPart = parts[1] -- The first argument passed is going to be the part we weld everything to
for a = 2, #parts do
-- Weld all other parts to the first part
weld(rootPart, parts[a])
end
end
local welds = weldBetween(script.Parent.Handle, script.Parent.P1, script.Parent.P2, script.Parent.P3, script.Parent.P4, script.Parent.P5, script.Parent.P6, script.Parent.P7, script.Parent.P8, script.Parent.P9, script.Parent.P10, script.Parent.P11, script.Parent.P12, script.Parent.P13, script.Parent.P14, script.Parent.P15, script.Parent.P16, script.Parent.P17, script.Parent.P18, script.Parent.P19, script.Parent.P20, script.Parent.P21, script.Parent.P22, script.Parent.P23, script.Parent.P24, script.Parent.P25, script.Parent.P26, script.Parent.P27, script.Parent.P28, script.Parent.P29, script.Parent.P30, script.Parent.P31, script.Parent.P32, script.Parent.P33, script.Parent.P34, script.Parent.P35, script.Parent.P36, script.Parent.P37)
Here's the weld script I'm using, which is a fixed version of my broken version. It welds fine, but the front surface thing is an issue and ruins the gun. Help?
