WOOFWOOF_HACKERS

Untitled

Oct 21st, 2021
954
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local startNextPath = game.ServerStorage.startNextPath.Value
  2.  
  3. while true do
  4.     if startNextPath == true then
  5.         startNextPath = false
  6.  
  7.         wait(0.2)
  8.  
  9.         local PathfindingService = game:GetService("PathfindingService")
  10.         local Players = game:GetService("Players")
  11.  
  12.         local path = PathfindingService:CreatePath({
  13.             Costs = {
  14.                 Crosswalk = 0.001,
  15.                 Sidewalk = 0.001,
  16.                 Grass = math.huge,
  17.                 Road = math.huge
  18.             }
  19.         })
  20.  
  21.         local character = script.Parent
  22.         local humanoid = character:WaitForChild("Humanoid")
  23.        
  24.         local randVec = Vector3.new(math.random() * 500, math.random() * 200, math.random() * 500)
  25.         local TEST_DESTINATION = randVec
  26.  
  27.         local waypoints
  28.         local nextWaypointIndex
  29.         local reachedConnection
  30.         local blockedConnection
  31.  
  32.         local function followPath(destination)
  33.             -- Compute the path
  34.             local success, errorMessage = pcall(function()
  35.                 path:ComputeAsync(character.PrimaryPart.Position, destination)
  36.             end)
  37.  
  38.             if success and path.Status == Enum.PathStatus.Success then
  39.                 -- Say that the path has been computed
  40.                 warn("Path copmputed")
  41.                 -- Get the path waypoints
  42.                 waypoints = path:GetWaypoints()
  43.  
  44.                 -- Detect if path becomes blocked
  45.                 blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
  46.                     -- Check if the obstacle is further down the path
  47.                     if blockedWaypointIndex >= nextWaypointIndex then
  48.                         -- Stop detecting path blockage until path is re-computed
  49.                         blockedConnection:Disconnect()
  50.                         -- Re-compute new path
  51.                         startNextPath = true
  52.                     end
  53.                 end)
  54.  
  55.                 -- Detect when movement to next waypoint is complete
  56.                 if not reachedConnection then
  57.                     reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
  58.                         if reached and nextWaypointIndex < #waypoints then
  59.                             -- Increase waypoint index and move to next waypoint
  60.                             nextWaypointIndex += 1
  61.                             humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
  62.                             startNextPath = false
  63.                         else
  64.                             reachedConnection:Disconnect()
  65.                             blockedConnection:Disconnect()
  66.                             startNextPath = true
  67.                         end
  68.                     end)
  69.                 end
  70.  
  71.                 -- Initially move to second waypoint (first waypoint is path start; skip it)
  72.                 nextWaypointIndex = 2
  73.                 humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
  74.             else
  75.                 warn("Path not computed, Recomputing.", errorMessage)
  76.                 startNextPath = true
  77.             end
  78.         end
  79.  
  80.         followPath(TEST_DESTINATION)
  81.     end
  82.     wait(0.1)
  83. end
  84.  
  85.  
  86.  
RAW Paste Data