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.
local damageWeapon = script.Parent.Parent.Damage -- .Value(!)
local canBeDisarmed = script.Parent.Parent.CanBeDisarmed
local bladeWeapon = script.Parent
local optionalTouchPartWeapon = script.Parent.Parent.Pole
local wielderHead = script.Parent.Parent.Parent.Head
local basicAttackAnim = script.Parent.Parent.Parent.Attack
local basicAttackAnimPlay = script.Parent.Parent.Parent.Humanoid:LoadAnimation(basicAttackAnim)
local attacking = false
--local touched = false
local canDamage = script.Parent.Parent.CanDamage
local function warnAttack()
wielderHead.AttackUI.SwordIcon.Visible = true
wielderHead.AttackUI.SwordIcon.ImageColor3 = Color3.fromRGB(255,0,0)
wait(0.2)
end
local function basicAttack()
--print(canDamage.Value)
basicAttackAnimPlay:Play()
wait(basicAttackAnimPlay.Length)
wielderHead.AttackUI.SwordIcon.ImageColor3 = Color3.fromRGB(0,255,0)
-- wait (math.randomseed(3,5))
optionalTouchPartWeapon.Touched:Connect(function(hit)
if canDamage.Value == true then
canDamage.Value = false
-- print("attacking")
--if touched == false then
--touched = true
if hit.Parent:FindFirstChild("Humanoid") then
-- if attacking == false then
-- attacking = true
if hit.Parent.Humanoid.IsBlocking.Value == false then
if hit.Parent.Humanoid.NPC.Value == false then
hit.Parent.Humanoid:TakeDamage(damageWeapon.Value)
bladeWeapon.HitSound:Play()
wait(2)
canDamage.Value = true
-- if target is blocking
elseif hit.Parent.Humanoid.NPC.Value == false
and hit.Parent.Humanoid.IsBlocking.Value == true then
bladeWeapon.BlockSound:Play()
bladeWeapon.Sparkles.Enabled = true
wait(0.2)
bladeWeapon.Sparkles.Enabled = false
wielderHead.AttackUI.SwordIcon.ImageColor3 = Color3.fromRGB(0,255,0)
wait(1)
wielderHead.AttackUI.SwordIcon.Visible = false
--elseif not hit.Parent:FindFirstChild("Humanoid") then
-- canDamage.Value = true
--else
--canDamage.Value = true
end
end
end
end
end)
end
while wait(0.5) do
if script.Parent.Parent.Parent.EnemyInSight.Value == true then
repeat
wait(2)
warnAttack()
basicAttack()
until script.Parent.Parent.Parent.EnemyInSight.Value == false
wielderHead.AttackUI.SwordIcon.Visible = false
end
end

5 comments
look for any errors by writing /console
Hey there, thanks for the reply. I'm afraid the output doesn't give any errors as far as I've seen.
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
I'm afraid it doesn't print anything. Really strange.
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"