Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Zombies onTouch Humanoid Kills other zombies instead of players?

I'm making zombies that takes damage when a player touches them and when the zombies detect their humanoid, but my problem is that the zombies have a humanoid has well. So when they are coming towards me and they touch each other, they take damage as well. How can I make it so that only the players take damage from them instead of them being able to kill each other?

Just to clarify, this does kill players AND zombies but I want it to only kill players.

Script inside of "LeftLowerArm" and "RightLowerArm"

function onTouched(hit)
    local human = hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) and (human.Parent.Name ~= "RoboZombie") then
           human.Health = human.Health - 5
	end
end
script.Parent.Touched:connect(onTouched)

1 comment

0

add in the if statement and game.Players:GetPlayerFromCharacter(hit.Parent)

1 answer

✓ Accepted answer
if human and game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
	human.Health = human.Health - 5
end

Try that in your if statement

1 comment

0

It Worked! Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.