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

How do I damage a player but not a zombie?

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

✓ Accepted answer

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

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