I added an anti-TK precaution to a sword script, however since then whenever it hit a part that was welded to a player such as armor, it stopped working.
I always get this error message: attempt to index nil with 'FindFirstChild' from the line containing "if humanoid" If I need to add an "else" statement, what should I do? How else can I improve this script?
if hit.Parent ~= nil then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local eTeam = hit.Parent:FindFirstChild("Team")
local vCharacter = sp.Parent
if vCharacter ~= nil then
local vPlayer = game.Players:playerFromCharacter(vCharacter)
if vPlayer ~= nil then
local hum = vCharacter:FindFirstChild("Humanoid")
local friendly = vCharacter:FindFirstChild("Team").Value
if humanoid then
print ("Enemy Found")
if eTeam then
print ("Team Found")
if humanoid ~= hum and eTeam.Value ~= friendly then
print ("Enemy Found")
local right_arm = vCharacter:FindFirstChild("Right Arm")
if right_arm ~= nil then
local joint = right_arm:FindFirstChild("RightGrip")
if joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword) then
sp.Handle['CutSound'..math.random(1, 2)]:Play()
tagHumanoid(humanoid,vPlayer)
humanoid:TakeDamage(damage)
wait(.3)
end
end
end
end
end
end
end
