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

Humanoid not taking damage when an Accessory is hit by the part?

Asked by 3 years ago

I've been trying at this for a while and I do understand why it's not working. I'm making my first simple gun and when the bullet hits the player, as in their arm or their torso then yes it does damage them, but when you hit their hat or something on their back it doesn't damage them. If someone could tell me why this is not working that'd be great, thank you!

    if part then
        if part.Parent:FindFirstChild("Humanoid") or part:IsA("Accessory") and part.Parent:FindFirstChild("Humanoid").Health > 0 then
            part.Parent.Humanoid:TakeDamage(Damage)
        end
    end

1 answer

Log in to vote
1
Answered by 3 years ago

The reason this doesn't work is because hat/accessory parts aren't in the player.Character. There layered deeper in player.Character.Hat.Handle

and example is this

the way you can fix this is by making your script look a little more like this

if part then
    local findhumanoid=part.Parent:FindFirstChild("Humanoid")
    if findhumanoid~=nil then
        findhumanoid:TakeDamage(Damage)
    else
        findhumanoid=part.Parent.Parent:FindFirstChild("Humanoid")
        if findhumanoid~=nil then
            findhumanoid:TakeDamage(Damage)
        end
    end
end
Ad

Answer this question