How to make AI switch between walking at random points and chasing player?

How can i make to several AI walk in random points, and whet i press 2, closest one starts to chase me?

P.S. I made first part, with walking on random points, but can’t understand how to make second