#Error I don't understand?

11 messages · Page 1 of 1 (latest)

safe cove
#

I'm trying to make it so that if a character touches another character and has more hp, The character that has less hp gets destroyed. I'm not talking about a player's character btw, But it's giving me this strange error that I don't understand "Script:3: attempt to index nil with 'Health'"
Please help

    local humanoid = other.Parent:FindFirstChild("Humanoid")
    if humanoid.Health > script.Parent.Humanoid.Health then
        script.Parent:Destroy()
    end
end

script.Parent.Humanoid.Touched:Connect(onTouched)
tame lintel
#

if the first variable doesnt get a humanoid it remains Nil

tame lintel
#
 function onTouched(other)
    local humanoid = other.Parent:FindFirstChild("Humanoid")
    if humanoid then
       if humanoid.Health > script.Parent.Humanoid.Health then
          script.Parent:Destroy()
       end
    end
end

script.Parent.Humanoid.Touched:Connect(onTouched)
#

should work

safe cove
#

Doesn't

#

Both characters do have a humanoid

tame lintel
#

what errors now

safe cove
#

Ah

#

I fixed it