Help with enemy NPC

So i have a combat script which i heavily edited, the script works fine for the player.

Im going to use this script for my enemy NPC as well, i need the NPC to play the attack animation once i get within a certain distance. How can i achieve this?

Also, would this script work inside of an NPC as it is or would i need to edit it?

1.You can get Distance player by using Magnitude so when player in range script will running

2.Yes you need to edit some script to make NPC attack

Ok i will look into it and see what i can come up with. And in terms of editing the script, would it work if i just added magnitude inside of the script?

it might work but I not sure about it

I maked a enemy NPC which works as a RPG game, i use MinDistance and MaxDistance so if the Distance is greater than the max Magnitude the NPC removes you from the Target, else if you’re between MinDistance and MaxDistance NPC will follow you, else if MinDistance greater than Distance will attack you, also i’m using 2 scritps to separate the walk and attack & remove script.