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

How do I damage a player but not a zombie?

Asked by
KordGamer 155
8 years ago

I am working on a zombie game and I am making a zombie that pukes damage bricks. The only problem with this is that the bricks hurt other zombies and hurts the zombie that is puking it.

This is the script for the kill brick. It doesn't damage anything now.

function touch(hit)
    if not hit.Parent.Name == "Zombie" then
    hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -50
    end
end

script.Parent.Touched:connect(touch)

Any help given is appreciated. Thank you!

1 answer

Log in to vote
1
Answered by 8 years ago

I suggest using GetPlayerFromCharacter() to check whither or not the Part/Object that triggered the touched event it controlled by an actual Player.

script.Parent.Touched:connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)--This check and see's if the Part/Object that triggered the event in controlled by a player and if it is then it will return with the Player's name otherwise it will return nil
    if Player then--If Part is controlled by player then...
        Player.Character.Humanoid:TakeDamage(50)--This prevent the zombies from damaging the Player when he/she has a ForceField on.
    end
end)

~ UserOnly16Charcters Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

Ad

Answer this question