Hi! So I am making a zombie system where a zombie follows a player and attacks it with a hitbox welded to the torso. So far the following script I got is working fine however if I make more than 1 zombie and they touch each other, they start damaging each other and I want only the player to be damaged. Someone told me I can use GetPlayerFromCharcter but I can't really understand how to use that since I've never heard of it. Here is the script that I'm trying to fix with GetPlayerFromCharacter. The script is attached to the hitbox whenever the player touches the hitbox:
function touch(hit)
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -3
end
script.Parent.Touched:connect(touch)
If you know how I can use GetPlayerFromCharacter to only let the zombies damage the players and not themselves, please tell me!
[Re-edited by JessseSong]
Fixed Grammar and code block!
- Date: 14/03/2021
- Time 20:23 (GMT)
Reference(s):

2 comments
What people mostly use GetPlayerFromCharacter is for seeing if whatever touched the part is a player
Basically touch events etc.