Are you using AI behaviour trees? If not google AI Behavior tree or start with this.
I think that is more simple to use, however if you want to do it manually couple of things should be done.
- AI MoveTo Target Location, while moving
- Checker Function : Is Target In Range ( can be min - max)
- If True: Do Slash, if not keep moving.
Do correct if its wrong answer, explain step by step what needs to happen.