How would i make an npc follow the closest player?

My current aim is to make a working enemy module thats easily customisable to allow it to be used for different types of monsters or enemies in my game.

The issue i’m having is that i can’t figure out a way for the npc’s body to constantly be looking at the closest player.

I’ve already managed to make the npc find the closest players character with ease but i’m struggling making the npc follow that characters torso on the horizontal axis. i don’t want it’s body up or down because they its body would clip through the floor instead i’d just make the head look up or down and i’ve managed to do that but the body won’t move for some reason.

-This game uses r6 characters.

-Also i’m not asking people to script the entire system for me i’m just looking for guidance to set me on the right track to finish the module.

https://devforum.roblox.com/search?q=npc%20closest

1 Like

If you look up TheDevKing’s Advanced Series Tutorial on Magnitude he explains exactly how to do this. He uses two dummy npc’s which have the same exact make-up as our characters. Once you see how Magnitude works in a scripting format, look up some other videos because there are videos on this topic specifically as well. I’m still rather new to scripting, but I’ve studied a ton and I’ve found REALLY digesting every aspect of how these scripts work, 1 by 1, makes it so much easier to comprehend and understand a full script.

Also his tutorial on Pathfinding.