Haven't ever used MS's before, so cut me some slack if I'm doing this all wrong.
ServerScript:
local weld = jar.WeldTo(root, c, v.Joints, 'relative') -- None of these arguments are nil
ModuleScript(named 'jar')
local jar = {}
function jar.WeldTo(a, b, jfolder, cframe)
local weld = Instance.new('Weld', jfolder)
weld.Name = 'Weld'
weld.Part0 = a -- Error: Bad Cast
weld.Part1 = b
if cframe == 'relative' then weld.C0 = a.CFrame:inverse() * b.CFrame
else weld.C0 = cframe end
return weld
end
return jar

2 comments
root is probably not a Part. The variable a which is Part0 needs to be fed a Part.
I recommend taking a look at this: https://scriptinghelpers.org/questions/7347/got-a-error-saying-bad-casthow-do-i-fix-it