local player = script.Parent.TargetPlayer.Value while true do wait() script.Parent.Humanoid:MoveTo(player.Torso.Position) end
this script is a simple pathfind. i want this script to work with distance so if the player is a 20 distance away from the npc then the npc will follow the player if the player is not 12 or above distance away from the npc the npc will not follow him. how would i do that on this script?
Alright, see if this works.
We have to use ".magnitude", which gets a number value from two positions.
local player = script.Parent.TargetPlayer.Value distance = 20 while true do wait() if (player.Torso.Position - (TheNPCsTorso).Position).magnitude <= distance then script.Parent.Humanoid:MoveTo(player.Torso.Position) end end
Change (TheNPCsTorso) to the pathway for your npc's torso and hopefully it will follow it.