Advertisement
Guest User

Untitled

a guest
Jun 27th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. Droid = script.Parent.Parent
  2. PFS = game:GetService('PathfindingService')
  3. Debris = game:GetService('Debris')
  4.  
  5. local currentPath
  6.  
  7. local function FollowPath(path)
  8. local distance
  9. for i, v in pairs(coordinates) do
  10. repeat
  11. if path ~= currentPath then
  12. break
  13. end
  14. distance = (v - Droid.Head.Position).magnitude
  15. wait()
  16. until distance < 2
  17. end
  18. end
  19.  
  20. while wait(2.8) do
  21. path = PFS:ComputeSmoothPathAsync(Droid.Head.Position, Droid.Head.PathTarget.Position, 512)
  22. currentPath = path
  23. coordinates = currentPath:GetPointCoordinates()
  24.  
  25. for i,v in pairs(coordinates) do
  26. local Part = Instance.new("Part", Droid.Head)
  27. Part.CFrame=CFrame.new(v)
  28. Part.Transparency = 0
  29. Part.Color = Color3.new(0.2, 0, 1)
  30. Part.Size = Vector3.new(1, 1, 1)
  31. Part.Anchored = true
  32. Part.CanCollide = false
  33. Part.Locked = true
  34. Part.Name = 'Path'
  35. Part.Touched:connect(function(hit)
  36. Part:Destroy()
  37. end)
  38. if path.Status == Enum.PathStatus.Success then
  39. Part.Color = Color3.new(0, 1, 0) -- green
  40. elseif path.Status == Enum.PathStatus.ClosestNoPath then
  41. Part.Color = Color3.new(1, 0, 0) -- red
  42. elseif path.Status == Enum.PathStatus.ClosestOutOfRange then
  43. Part.Color = Color3.new(0.5, 0.75, 0) -- yellow
  44. elseif path.Status == Enum.PathStatus.FailStartNotEmpty then
  45. Part.Color = Color3.new(0.5, 0, 0.5) -- purple
  46. elseif path.Status == Enum.PathStatus.FailFinishNotEmpty then
  47. Part.Color = Color3.new(0.5, 0, 0.5) -- purple
  48. end
  49. Debris:AddItem(Part, 20.8)
  50. end
  51.  
  52. FollowPath(path)
  53. end
  54.  
  55. for i, v in pairs(coordinates) do
  56. Droid.Humanoid:MoveTo(v)
  57. repeat
  58. distance = (v - Droid.Head.Position).magnitude
  59. wait()
  60. until distance < 2
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement