I have an idea for how it is done.
You have a constant test being run that tests the distance of all players with a raycast. If a player comes close enough, then you have a simple command that causes your player to face the raycast, and attack.
I'm busy with other stuff though, so get someone else to do it.