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! 