Facebook
From SeekScript, 10 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 150
  1. local PathfindingService = game:GetService("PathfindingService")
  2. local Debris = game:GetService("Debris")
  3. local Players = game:GetService("Players")
  4.  
  5. local Demon = script.Parent.DemonType
  6. local destination = nil
  7. local path = nil
  8.  
  9. local function updatePath()
  10.  if destination and destination.Character and destination.Character:FindFirstChild("HumanoidRootPart") then
  11.   local humanoidRootPart = destination.Character.HumanoidRootPart
  12.   local distance = (Demon.RootPart.Position - humanoidRootPart.Position).magnitude
  13.   if distance < 50 then
  14.    path = PathfindingService:CreatePath({
  15.     AgentRadius = 2;
  16.     AgentHeight = 5;
  17.     AgentCanJump = false;
  18.    })
  19.    path:ComputeAsync(Demon.RootPart.Position, humanoidRootPart.Position)
  20.    if path.Status == Enum.PathStatus.Success then
  21.     return path:GetWaypoints()
  22.    end
  23.   end
  24.  end
  25.  return nil
  26. end
  27.  
  28. local function followPath(waypoints)
  29.  for _, waypoint in ipairs(waypoints) do
  30.   Demon:MoveTo(waypoint.Position)
  31.   Demon.MoveToFinished:Wait()
  32.  end
  33. end
  34.  
  35. while true do
  36.   destinati
  37.  
  38.  if destination then
  39.   local waypoints = updatePath()
  40.   if waypoints then
  41.    followPath(waypoints)
  42.   else
  43.    Demon:MoveTo(game.Workspace.Spawners.Spawner.SpawnPoint.Position + Vector3.new(math.random(10), 0, math.random(10)))
  44.    Demon.MoveToFinished:Wait()
  45.   end
  46.  else
  47.   Demon:MoveTo(game.Workspace.Spawners.Spawner.SpawnPoint.Position)
  48.  end
  49.  
  50.  wait(0.0001)
  51. end
  52.