Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid's health won't TakeDamage on Touch?

Asked by
emite1000 335 Moderation Voter
10 years ago

I created a Tool with only a brick and a script in it. I created a humanoid with only a part named Head in it. When the Tool touches the Humanoid part, the humanoid should lose 10 health. But nothing happens.

The script:

script.Parent.Handle.Touched:connect(function(part)
    part.Parent:FindFirstChild("Humanoid")
    if found then
        Humanoid:TakeDamage(10)
    end
end)

What's wrong?

1 answer

Log in to vote
0
Answered by 10 years ago

I'm not sure what you mean by if found then, because that wouldn't work. Also you didn't define Humanoid. You could simply do it like this:

script.Parent.Handle.Touched:connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum ~= nil then
        hum:TakeDamage(10)
    end
end)
0
I thought that the hit event only applied to Explosions? Why are you using it here? emite1000 335 — 10y
0
hit is just the function name. systematicaddict 295 — 10y
Ad

Answer this question