Advertisement
Mangus875

Nextbot creator (WIP)

Apr 10th, 2023 (edited)
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local function createNextbot(image: number | string, name : string)
  2.     local bot = Instance.new("Model")
  3.     bot.Name = name or "Nextbot"
  4.    
  5.     local controller    -- find a way to make a humanoid thing
  6.     local chaseVal = Instance.new("IntegerValue", bot)
  7.     chaseVal.Name = "Chasing"
  8.    
  9.     local pfs = game:GetService("PathFindingService")
  10.     local targets = {}
  11.     task.spawn(function()
  12.         while true do
  13.             if not chaseVal.Value then task.wait() continue end
  14.             --
  15.             local nearest = nil
  16.             for _, v in pairs(game.Players:GetPlayers()) do
  17.                 local chr = v.Character
  18.                 local hrp = chr:FindFirstChild("HumanoidRootPart")
  19.                 if hrp then
  20.                     if not nearest or (hrp.Position - controller.PrimaryPart).Magnitude < (nearest.Position - controller.PrimaryPart).Magnitude then
  21.                         nearest = hrp
  22.                     end
  23.                 end
  24.             end
  25.             if nearest then
  26.                 local path = pfs:CreatePath()
  27.                 path:ComputeAsync(controller.PrimaryPart.Position, nearest.Position)
  28.                 local wps = path:GetWaypoints()
  29.                 for _, w in pairs(wps) do
  30.                     controller.Humanoid:MoveTo(w.Position)
  31.                     controller.Humanoid.MoveToFinished:Wait()
  32.                 end
  33.             end
  34.             --
  35.             task.wait(0.5)
  36.         end
  37.     end)
  38.     bot.Parent = workspace
  39.     return bot
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement