Good afternoon,
I keep getting a bad cast in the output whenever i click the ShirtBttn2 for the second function. The model is cloned to the NPC from ReplicatedStorage, however, it's position remains in the original position put in ReplicatedStorage, but not attactched to the Torso of the NPC. The bad cast call was in Line 59: "W.Part1 = C[i]". Anyone have any suggestions or ideas on how to fix this? Thank you, for your time.
Respectfully,
sparkevin
local ShirtBttn1 = sp:WaitForChild('Shirt1Button')
local ShirtBttn2 = sp:WaitForChild('Shirt2Button')
ShirtBttn1.MouseButton1Down:Connect(function()
if workspace.CurrentCamera:findFirstChild("CustomCharacter") ~= nil and game.ReplicatedStorage:findFirstChild("Chest1") == nil then
local g = game.ReplicatedStorage.Shirts.Chest1:clone()
local d = game.Workspace.CurrentCamera:FindFirstChild("CustomCharacter")
g.Parent = d
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" or "Union" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = d["UpperTorso"]
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, -0.5, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or "Union" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end)
ShirtBttn2.MouseButton1Down:Connect(function()
if workspace.CurrentCamera:findFirstChild("CustomCharacter") ~= nil and game.ReplicatedStorage:findFirstChild("Chest2") == nil then
local g = game.ReplicatedStorage.Shirts.Chest2:clone()
local d = game.Workspace.CurrentCamera:FindFirstChild("CustomCharacter")
g.Parent = d
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" or "Union" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = d["UpperTorso"]
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, -0.5, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "Part" or "Union" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
end)

2 comments
Have you tried print debugging
findFirstChild is deprecated, instead use FindFirstChild (capital F)