I'm trying to weld all the parts in this model to the Handle. But it keeps on giving me an error saying bad cast. I don't know how I would do this.
local module = {}
function module.WeldWepTArm(chr, wep)
local clonew = wep:Clone()
clonew.Name = "Weapon"
clonew.Parent = chr
local weld1 = Instance.new("Weld", clonew.Handle)
weld1.Part0 = clonew.Handle
weld1.Part1 = chr["Left Arm"]
weld1.C0 = CFrame.new(-0.1, 0, -1)*CFrame.fromEulerAnglesXYZ(0, -math.pi/2, math.pi/2)
local function weldBetween(a, b)
local weld = Instance.new("ManualWeld", a)
weld.Part0 = a
weld.Part1 = b
weld.C0 = a.CFrame:inverse() * b.CFrame
return weld
end
local parts = clonew:GetChildren()
for i,v in pairs(clonew:GetChildren()) do
if v.Name ~= "Handle" then
weldBetween(v, clonew.Handle) -- error here, saying bad cast
end
end
local cloneww = wep:Clone()
cloneww.Name = "WepOnBack"
cloneww.Parent = chr
local weld2 = Instance.new("Weld", cloneww.Handle)
weld2.Part0 = cloneww.Handle
weld2.Part1 = chr.Torso
weld2.C0 = CFrame.new(1, 0.6, 0)*CFrame.fromEulerAnglesXYZ(math.pi/2, 0, math.pi/4)
for i,v in ipairs(cloneww:GetChildren()) do
if v.ClassName == "Part" then
v.Transparency = 1
end
end
end
return module
