Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Enemy NPC not doing damage. Does this have something to do with debounce?

Asked by
souflee 50
4 years ago

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.

01local damageWeapon = script.Parent.Parent.Damage -- .Value(!)
02local canBeDisarmed = script.Parent.Parent.CanBeDisarmed
03local bladeWeapon = script.Parent
04local optionalTouchPartWeapon = script.Parent.Parent.Pole
05local wielderHead = script.Parent.Parent.Parent.Head
06 
07local basicAttackAnim = script.Parent.Parent.Parent.Attack
08local basicAttackAnimPlay = script.Parent.Parent.Parent.Humanoid:LoadAnimation(basicAttackAnim)
09local attacking = false
10--local touched = false
11local canDamage = script.Parent.Parent.CanDamage
12 
13local function warnAttack()
14    wielderHead.AttackUI.SwordIcon.Visible = true
15    wielderHead.AttackUI.SwordIcon.ImageColor3 = Color3.fromRGB(255,0,0)
View all 75 lines...
0
look for any errors by writing /console TheUltimateTNTFriend 109 — 4y
0
Hey there, thanks for the reply. I'm afraid the output doesn't give any errors as far as I've seen. souflee 50 — 4y
0
try make it print something after "if hit.Parent.Humanoid.NPC.Value = false then" and if it does print something then must be a error with how ur damaging him TheUltimateTNTFriend 109 — 4y
0
I'm afraid it doesn't print anything. Really strange. souflee 50 — 4y
0
I think it's a problem with the debounce or the onTouched function as it doesn't print anything after "if hit.Parent.Humanoid.NPC.Value == false then" souflee 50 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

I pretty the problem is in the basicAttack function at line 41. The canDamage value only changes if hit.Parent.Humanoid.IsBlocking.Value == false and hit.Parent.Humanoid.NPC.Value == false. If the hit thing is blocking or is a npc then the rest of the code isn't allowed to be run which stops the canDamage from being set to true. So basically move the canDamage outside of the if statements as seen below.

01local damageWeapon = script.Parent.Parent.Damage -- .Value(!)
02local canBeDisarmed = script.Parent.Parent.CanBeDisarmed
03local bladeWeapon = script.Parent
04local optionalTouchPartWeapon = script.Parent.Parent.Pole
05local wielderHead = script.Parent.Parent.Parent.Head
06 
07local basicAttackAnim = script.Parent.Parent.Parent.Attack
08local basicAttackAnimPlay = script.Parent.Parent.Parent.Humanoid:LoadAnimation(basicAttackAnim)
09local attacking = false
10--local touched = false
11local canDamage = script.Parent.Parent.CanDamage
12 
13local function warnAttack()
14    wielderHead.AttackUI.SwordIcon.Visible = true
15    wielderHead.AttackUI.SwordIcon.ImageColor3 = Color3.fromRGB(255,0,0)
View all 79 lines...
0
Hey there! Thanks for the informative reply. Do pardon me for my late response, I was asleep when you posted this. I tried out your instructions and did as you said, but the script became very unreliable, it now does damage at seemingly random rather than doing damage when the attack is performed. I possibly (sort of) found a solution. I'll post it down here. Thanks again for your reply. souflee 50 — 4y
Ad
Log in to vote
0
Answered by
souflee 50
4 years ago

Alright, lassies and gents - I may have found the solution. I'm not sure what I did, but I'll post the script down below, only problem I currently have with it is that it doesn't register when the player is blocking. Thank you all for your replies (I'm very grateful for that), any more help would be greatly appreciated

001local PathfindingService = game:GetService("PathfindingService")
002math.randomseed(tick())
003 
004--local counter = 1
005 
006local enemySpotted = false
007local CurrentPart = nil
008local MaxInc = 16
009 
010local walkAnim = script.Parent.Walk
011local walkAnimPlay = script.Parent.Humanoid:LoadAnimation(walkAnim)
012 
013local idleAnim = script.Parent.Idle
014local idleAnimPlay = script.Parent.Humanoid:LoadAnimation(idleAnim)
015 
View all 133 lines...

Answer this question