To accomplish this, you could use the handy dandy method :GetPlayerFromCharacter(). What that method does is ensures if a character is an actual player or an NPC(Zombie in your case).
To give an example of this, I inserted the generic classic paintball gun you can find under ROBLOX sets in the toolbox. In the Paintball script of this gun, its where we use the .Touched event on the bullet.(Gets cloned into the bullet)
The block of code that manages damage to the humanoid in that script is as followed:
if humanoid ~= nil
tagHumanoid(humanoid)
humanoid:TakeDamage(damage)
wait(2)
untagHumanoid(humanoid)
end
That code will take damage on both players and Zombies. To fix that, we will use GetPlayerFromCharacter() method.
You would change the if statement to this:
if(humanoid~=nil and not game.Players:GetPlayerFromCharacter(hit.Parent)) then
That code checks if hit.Parent(which would be the legs,arms,head or torso's Parent(Character)) is indeed a player. We use not which basically reverts the statement, so if its not a player.
The final block of code should look like this:
if humanoid ~= nil and not game.Players:GetPlayerFromCharacter(hit.Parent) then
tagHumanoid(humanoid)
humanoid:TakeDamage(damage)
wait(2)
untagHumanoid(humanoid)
end
Cheers!
1 comment
Use if not game.Players:GetPlayerFromCharacter(character) then character:TakeDamage(20) end) If its false then its not a real player!