Problem with Hit AI

I’m currently having trouble with this “Hit AI” script. Parented into a character, what it does is detect if the character is punched by someone. The thing is, despite the Humanoid supposing to take 10 pts of damage, when the character is punched, the character instantly dies

HitAI Script:

wait(5) --Waits for Character to fully load

local EnemyCharacter = script.Parent
local EnemyHumanoid = EnemyCharacter.Humanoid
local canBeDamaged = true --Debounce

EnemyCharacter.HumanoidRootPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local LeftArm = hit.Parent:FindFirstChild("Left Arm")
		local isAttackingVal = hit.Parent:FindFirstChild("isAttacking") --A value inside the player that shows if he/she is attacking
		if hit == LeftArm then
			if canBeDamaged and isAttackingVal.Value == true then --If the player is attacking and ememy can be damaged
				canBeDamaged = false
				EnemyHumanoid:TakeDamage(10) --Enemy takes 10 damage
				print("Enemy has been damaged!")
				wait(1)
				canBeDamaged = true
			end
		end
	end
end)

Was there an error in the script or a bug? Let me know as soon as possible! :smiley:

Snipping this post, nothing to see here.

Snipping this post, nothing to see here.

wait(5) --Waits for Character to fully load

local EnemyCharacter = script.Parent
local EnemyHumanoid = EnemyCharacter.Humanoid
local canBeDamaged = true --Debounce

EnemyCharacter.HumanoidRootPart.Touched:Connect(function(hit)
	if not canBeDamaged then
		return
	end
	if hit.Parent:FindFirstChild("Humanoid") then
		local isAttackingVal = hit.Parent:FindFirstChild("isAttacking") --A value inside the player that shows if he/she is attacking
		if hit.Name == "Left Arm" then
			if isAttackingVal.Value then --If the player is attacking and ememy can be damaged
				canBeDamaged = false
				EnemyHumanoid.Health -= 10 --Enemy takes 10 damage
				print("Enemy has been damaged!")
				task.wait(1)
				canBeDamaged = true
			end
		end
	end
end)

Everything seemed fine before, I made some minor changes.