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 4 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!

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

1 answer

Log in to vote
1
Answered by 4 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

01if part then
02    local findhumanoid=part.Parent:FindFirstChild("Humanoid")
03    if findhumanoid~=nil then
04        findhumanoid:TakeDamage(Damage)
05    else
06        findhumanoid=part.Parent.Parent:FindFirstChild("Humanoid")
07        if findhumanoid~=nil then
08            findhumanoid:TakeDamage(Damage)
09        end
10    end
11end
Ad

Answer this question