NPC that runs from a specific part

Basically, I want to make a script that makes an npc run away from a certain part, like a shotgun when you pull it out.

I’m not smart at all, and i’m new to scripting so i’m not sure how I would do this.

I’ve been researching but can’t figure it out.

Well you can check the distance between the part and the NPC using magnitude and if the NPC is close enough you can make it run away. You can use the Pathfinding Service to make the player run or away or just use Humanoid:MoveTo(vector3).

1 Like

thanks for the info, i’ll look into it.

Sorry, can you explain magnitude to me?

1 Like

Checking a distance between two positions.

1 Like

magnitude returns the amount of studs between two different instances. You can use it like this:

local magnitude = (myFirstPart.Position - mySecondPart.Position).magnitude
print(magnitude)

and how do I use pathfindingservice