Why Wont This Pathfind Script Work?
01 | local p = game:GetService( "PathfindingService" ) |
03 | local target = script.Parent.Target.Value.Torso |
04 | local v = script.Parent |
05 | local parts = script.Parent:GetChildren() |
06 | local path = p:ComputeRawPathAsync(v.Torso.Position,target.Position, 500 ) |
07 | if (v.Torso.Position-target.Position).magnitude< 4 and target~ = v.Torso then |
10 | local points = path:GetPointCoordinates() |
13 | local part,point = workspace:FindPartOnRay(Ray.new(points [ math.min(#points,i) ] ,Vector 3. new( 0 ,- 10 , 0 ))) |
14 | local part,point 2 = workspace:FindPartOnRay(Ray.new(points [ math.min(#points,i+ 1 ) ] ,Vector 3. new( 0 ,- 10 , 0 ))) |
16 | while math.min((point 2 -v.Torso.Position).magnitude,(point*Vector 3. new( 1 , 0 , 1 )-v.Torso.Position*Vector 3. new( 1 , 0 , 1 )).magnitude)> 3 and count< 50 do |
18 | v.Humanoid:MoveTo(point 2 ) |
19 | if workspace:FindPartOnRay(Ray.new(v.Torso.Position,CFrame.new(v.Torso.Position*Vector 3. new( 1 , 0 , 1 ),point 2 *Vector 3. new( 1 , 0 , 1 )).lookVector* 4 )) then |
20 | v.Humanoid:MoveTo(point) |
22 | if workspace:FindPartOnRay(Ray.new(v.Torso.Position,CFrame.new(v.Torso.Position*Vector 3. new( 1 , 0 , 1 ),point*Vector 3. new( 1 , 0 , 1 )).lookVector* 3 )) then |
29 | v.Humanoid:MoveTo(target.Position) |
30 | if target.Position.Y> = v.Humanoid.Torso.Position.Y+ 1 then |
this is a pathfinding script. i want this to make the the NPC that has this script in him to follow the target. but it doesnt follow him. it moves to 1 place then stops there. it doesnt follow the player right. please can you help me with this.