So I've got a morph, which has several parts, 2 models, a gui and 2 local scripts, but when I try to weld these via my script, they are producing this error.
15:58:45.223 - bad cast
15:58:45.224 - Script 'Workspace.IBH.Head.Torso', Line 13
15:58:45.224 - Stack End
I know you can't weld models and scripts, but I don't know how to avoid it.
function onTouch(hit)
if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("BTorso") == nil then
local suit = script.Parent.Parent["BTorso"]:clone()
suit.Parent = hit.Parent
local G = suit:getChildren()
for i=1, #G do
if G[i].className == "Part" or "Unionoperation" then
local suitW = Instance.new("Weld")
suitW.Part0 = suit.MainPart
suitW.Part1 = G[i]
local autoW = CFrame.new(suit.MainPart.Position)
suitW.C0 = suit.MainPart.CFrame:inverse()*autoW
suitW.C1 = G[i].CFrame:inverse()*autoW
suitW.Parent = suit.MainPart
end
local bpW = Instance.new("Weld")
bpW.Part0 = hit.Parent["Torso"]
bpW.Part1 = suit.MainPart
bpW.C0 = CFrame.new(0, 0, 0)
bpW.Parent = suit.MainPart
end
local c = suit:getChildren()
for i=1, #c do
c[i].Anchored = false
c[i].CanCollide = false
end
end
end
script.Parent.Touched:connect(onTouch)
