So I was currently fixing and improving the enemies’ AI by allowing them to roll quickly on the ground. What should happen is that after the enemy rolls near the player, they attack.
The problem is that when the enemies finish rolling, they don’t attack the player.
Here’s the part of the AI that controls the attacking and roll action of the enemy:
if torso then
local distance = (EnemyTorso.Position - torso.Position).magnitude
local plrRoot = torso.Parent:FindFirstChild("HumanoidRootPart")
EnemyHumanoid:MoveTo(plrRoot.Position - CFrame.new(EnemyHRP.Position, plrRoot.Position).LookVector * AttackRange) --Makes the Enemy run towards the player
if distance <= AttackRange + 1.5 and not script.Parent:FindFirstChild("Hit") then --When the enemy is close enough to attack the player
script.AttackEvent:Fire(plrRoot)
end
if not RollDebounce.Value then --Problem is right here
RollDebounce.Value = true
local BV = Instance.new("BodyVelocity")
local RollAnim = EnemyHumanoid:LoadAnimation(script.RollAnim)
BV.Parent = EnemyHRP
RollAnim:Play()
BV.MaxForce = Vector3.new(10000, 10000, 10000)
BV.Velocity = EnemyHRP.CFrame.LookVector * 40
Debris:AddItem(BV, 0.475)
RollDebounce.Times.Value = RollDebounce.Times.Value - 1
end
end
Is there anything I’ve misplaced or that I need to fix? Thanks in advance!