Enemy NPC not doing damage. Does this have something to do with debounce?
Hey there, I've been scripting for quite a while now, but this is one of the first times I'm asking a question.
In a nutshell, I have an enemy NPC (pathfinding is in another script), the goal is to have a gui with a sword pop up above his head and have it turn red when he begins an attack (here an onTouched function begins to check if the player is blocking the attack or not, so that he does damage), then have it turn green when he's no longer attacking.
This in itsself works fine except for the damage part. I've tried alot of things by now (I've highlighted some of the code I tried), but it just refuses to work. I've also added a BoolValue as debounce, perhaps the problem is in said BoolValue? I'm out of ideas by now. Any help would be greatly appreciated.
01 | local damageWeapon = script.Parent.Parent.Damage |
02 | local canBeDisarmed = script.Parent.Parent.CanBeDisarmed |
03 | local bladeWeapon = script.Parent |
04 | local optionalTouchPartWeapon = script.Parent.Parent.Pole |
05 | local wielderHead = script.Parent.Parent.Parent.Head |
07 | local basicAttackAnim = script.Parent.Parent.Parent.Attack |
08 | local basicAttackAnimPlay = script.Parent.Parent.Parent.Humanoid:LoadAnimation(basicAttackAnim) |
09 | local attacking = false |
11 | local canDamage = script.Parent.Parent.CanDamage |
13 | local function warnAttack() |
14 | wielderHead.AttackUI.SwordIcon.Visible = true |
15 | wielderHead.AttackUI.SwordIcon.ImageColor 3 = Color 3. fromRGB( 255 , 0 , 0 ) |
19 | local function basicAttack() |
21 | basicAttackAnimPlay:Play() |
22 | wait(basicAttackAnimPlay.Length) |
23 | wielderHead.AttackUI.SwordIcon.ImageColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
26 | optionalTouchPartWeapon.Touched:Connect( function (hit) |
27 | if canDamage.Value = = true then |
28 | canDamage.Value = false |
33 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
36 | if hit.Parent.Humanoid.IsBlocking.Value = = false then |
37 | if hit.Parent.Humanoid.NPC.Value = = false then |
38 | hit.Parent.Humanoid:TakeDamage(damageWeapon.Value) |
39 | bladeWeapon.HitSound:Play() |
41 | canDamage.Value = true |
43 | elseif hit.Parent.Humanoid.NPC.Value = = false |
44 | and hit.Parent.Humanoid.IsBlocking.Value = = true then |
46 | bladeWeapon.BlockSound:Play() |
47 | bladeWeapon.Sparkles.Enabled = true |
49 | bladeWeapon.Sparkles.Enabled = false |
50 | wielderHead.AttackUI.SwordIcon.ImageColor 3 = Color 3. fromRGB( 0 , 255 , 0 ) |
52 | wielderHead.AttackUI.SwordIcon.Visible = false |
67 | if script.Parent.Parent.Parent.EnemyInSight.Value = = true then |
72 | until script.Parent.Parent.Parent.EnemyInSight.Value = = false |
73 | wielderHead.AttackUI.SwordIcon.Visible = false |