This is just a damage script I put in my AI. I'm not sure why but when I hit them with a sword, there is no error but error appeared when I shot them with a bow. I guess that they computer might thought that I mean it differently because I clone an arrow into my tool when I shoot.
local cool = false
local slash = script:WaitForChild("Slash")
local human = script.Parent.Parent:FindFirstChildWhichIsA("Humanoid")
local anim2 = human:LoadAnimation(slash)
script.Parent.Touched:Connect(function(hit)
if cool == false and script ~= nil then
if hit.Parent:FindFirstChildOfClass("Humanoid") then -- error here
local enemy = hit.Parent:FindFirstChildOfClass("Humanoid")
if hit.Parent ~= script.Parent.Parent and enemy.Name ~= human.Name then
cool = true
anim2:Play()
enemy.Health = enemy.Health - 15
wait(2)
cool = false
end
end
end
end)
Help please. Thankyou.

5 comments
To diagnose, try printing the "hit" object. Does "hit" return anything? Like a name?
Yes I did, but they said a there's a new error, attempt to index nil with "Name" on the line that I wrote print(hit.Parent.Name)
Urgh, sometimes the error just appear and other times it doesn't, this is annoying.
Can you do print(hit) instead? It'll tell if it says "This object is not a valid member of ."
Yep, I just tried that and it did print the object name with no error