Axolotleless

Axo's nextbots ai Script

Apr 5th, 2025 (edited)
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. script.Parent.PrimaryPart:SetNetworkOwner(nil)
  2.  
  3. local RunS = game:GetService('RunService')
  4. local PFS = game:GetService('PathfindingService')
  5. --local debris = game:GetService("Debris")
  6.  
  7. local bot = script.Parent -- bot stuff
  8. local bhum = bot:WaitForChild('Humanoid')
  9. local bhrp = bot:WaitForChild('HumanoidRootPart')
  10.  
  11. local findPath = PFS:CreatePath({WaypointSpacing = math.huge})
  12. local actPath = PFS:CreatePath({WaypointSpacing = math.huge})
  13.  
  14. local followedChar -- the one we are already following
  15.  
  16. local char -- the one which we follow
  17.  
  18. local function nearestChar()
  19.     while wait() do
  20.         local nearChar, nearDist = nil, nil
  21.         local distance
  22.         local firstPos
  23.  
  24.         for i,v in pairs(workspace:GetChildren()) do
  25.             if v:FindFirstChild('Humanoid') and v ~= bot and not (v:FindFirstChild('Nextbot') or v:FindFirstChild('NPC')) and v.Humanoid.Health > 0 and v:FindFirstChild('HumanoidRootPart') then
  26.                 findPath:ComputeAsync(bhrp.Position, v.HumanoidRootPart.Position)
  27.                 if findPath.Status == Enum.PathStatus.Success then
  28.                     distance = 0
  29.                     for i,waypoint in ipairs(findPath:GetWaypoints()) do
  30.                         if i ~= 1 then
  31.                             distance = distance + (waypoint.Position - firstPos).Magnitude
  32.                         end
  33.                         firstPos = waypoint.Position
  34.                     end
  35.                     if nearDist == nil then
  36.                         nearDist = distance
  37.                         nearChar = v
  38.                     else
  39.                         if distance < nearDist then
  40.                             nearDist = distance
  41.                             nearChar = v
  42.                         end
  43.                     end
  44.                 end
  45.             end
  46.         end
  47.         char = nearChar
  48.     end
  49. end
  50.  
  51. spawn(nearestChar)
  52.  
  53. local count = 0
  54.  
  55. RunS.Heartbeat:Connect(function()
  56.     if count >= 3 then
  57.         count = 0
  58.         if char ~= nil and char:FindFirstChild('HumanoidRootPart') then
  59.             actPath:ComputeAsync(bhrp.Position, char.HumanoidRootPart.Position)
  60.             for i,v in ipairs(actPath:GetWaypoints()) do
  61.                 if i ~= 1 then
  62.                     bhum:MoveTo(v.Position)
  63.                     bhum.MoveToFinished:Wait()
  64.                 end
  65.             end
  66.         end
  67.     else
  68.         count = count + 1
  69.     end
  70. end)
  71.  
Advertisement
Add Comment
Please, Sign In to add comment