:TakeDamage Not Working?

  1. What do you want to achieve?
    I want the Player to take 15 damage and the armor will take 25 damage when equipped. When the armor’s health is 0, the Player takes 25 damage
  2. What is the issue?
    Once the Player puts on the armor, they will always take 15 damage, even if the armor’s health is 0
  3. What solutions have you tried so far?
    I’ve tried to check if the armor is equipped, because the bool value does change, but it doesn’t seem like the if statement is registering or something like that. I’ve tried look for similar problems like mine, but I haven’t found any.

The equipped value is a BooleanValue in Replicated Storage.
The armorHP value is an IntValue in workspace under a folder named “Armor”, there are two number attributes to it. Health and Maxhealth, both are 250. The value in the IntValue is 0.

I took a script from Y3llow Mustang’s Zombie Advanced AI Tutorial and modified to do damage to armor. These are the two functions I made/modified.

local function detectDamage(target, Damage)
	local damageHolder = 0
	
	local player = target.Parent
	local lPlayer = game.Players:GetPlayerFromCharacter(player)
	local armorBackGround = lPlayer.PlayerGui.ArmorGui.ArmorBackground

	local armorHP = workspace.Armor.armorHP
	local atriArmor = armorHP:GetAttribute("Health")
	if equipped.Value == true and atriArmor > 0 then

		armorBackGround = true
		
		local MaxatriArmor = armorHP:GetAttribute("MaxHealth")
		local healthBar = atriArmor/atriArmor
		print(armorHP:GetAttribute("Health"))

		armorHP:SetAttribute("Health",atriArmor - Damage) --Decreases HP of Armor

		print(armorHP:GetAttribute("Health"))
		--damageHolder = Damage --Holds in Damage from takeDamage
		print("The armor detected damage!")

	else
		--print("THE HUMAN IS TAKING DAMAGE")

		equipped.Value = false
		--armorBackGround = false

	end
end
 
function attack(target)
	if (myRoot.Position - target.Position).magnitude < 5 then
		local armorHealth = playerArmorNum:GetAttribute("Health")
		grabAnim:Play()
		grabSound:Play()
		
		if target.Parent ~= nil then
			if equipped.Value == true  then
				target.Parent.Humanoid:TakeDamage(15)
				print("Armor has TAKEN DAMAGE IDRGNDFNDFGKHHHHHHH")
				detectDamage(target, 25)
				
			else
				print("Human is TAKING DAMAGE AGGGGGGGGHHHHHH")
				target.Parent.Humanoid:TakeDamage(25)
			end
		end
		wait(1)
	end
end