Zombie script problem

Hi i am a new scripter. I have very limited scripting knowledge

I am making a zombie game, My script kinda works…

When the zombie hits the player the player gets damaged, If the zombie hits the player the second time the player does not take damage.

Also there is nothing in the output.

I think this is the part of the script to do with the attacking, if it is not, willing to provide the other parts of the script.

local humanoid = mob.Zombie – Zombie is the humanoid but renamed so zombies don’t damage each other

humanoid.Touched:Connect(function(hitPart)

if not isAttacking then return end


local character = hitPart.Parent

if character:FindFirstChild("Humanoid") then
	
	isAttacking = false
	
	character.Humanoid:TakeDamage(damagePerHit)
end

end)

1 Like

Make isAttacking = true after doing damage the first time.

2 Likes

maybe add a bool value to the player instead of changing the Zombies Humanoid name so they dont hurt each other

2 Likes

I did that, but now Zombies one shot me

maybe add a wait?

humanoid.Touched:Connect(function(hitPart)

if not isAttacking then return end


local character = hitPart.Parent

if character:FindFirstChild("Humanoid") then
	
	isAttacking = true
	
	character.Humanoid:TakeDamage(damagePerHit)
end

end)

1 Like

Don’t exactly know how to do that :frowning:

1 Like

Oh you have to do it AFTER the character does damage, so you would basically have both.

if character:FindFirstChild("Humanoid") then
	
	isAttacking = false
	
	character.Humanoid:TakeDamage(damagePerHit)

	wait(CooldownNumberToPutBeforeItCanHurtAgain)
	isAttacking = true
end
3 Likes

Thank you but my animation is not working…

if closestCharacter then

	humanoid:MoveTo(closestCharacter.HumanoidRootPart.Position)
	
	if not isCoolingDown and (closestCharacter.HumanoidRootPart.Position - mob.HumanoidRootPart.Position).Magnitude <= hitRange then
		
		isCoolingDown = true
		
		
		attackAnimation:Play()
		isAttacking = true
		
		attackAnimation.Stopped:Wait()
		isAttacking = false
		
		
		wait(hitCooldown)
		isCoolingDown = false
	end
end

end)

1 Like