Cleetaros
(Goon)
September 22, 2020, 1:54pm
1
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.
Synteuro
(Synteuro)
September 22, 2020, 1:57pm
2
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
Cleetaros
(Goon)
September 22, 2020, 1:58pm
3
thanks for the info, i’ll look into it.
Cleetaros
(Goon)
September 22, 2020, 1:59pm
4
Sorry, can you explain magnitude to me?
1 Like
koi_code
(koi)
September 22, 2020, 2:00pm
5
Checking a distance between two positions.
1 Like
Synteuro
(Synteuro)
September 22, 2020, 2:00pm
6
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)
Cleetaros
(Goon)
September 22, 2020, 2:13pm
7
and how do I use pathfindingservice