Advertisement
GForcebit

tiny blocks that pathfind

Mar 27th, 2021
3,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local prefix = "/"
  2.     local function command(name, f)
  3.         owner.Chatted:connect(function(v)
  4.             local nl = name:len() + 1
  5.             if v:len() >= nl and v:sub(1, 1) == prefix and v:sub(2, nl) == name then
  6.                 local chunks = {}
  7.                 for substring in v:sub(nl + 1):gmatch("%S+") do
  8.                     table.insert(chunks, substring)
  9.                 end
  10.                 f(unpack(chunks))
  11.             end
  12.         end)
  13. end
  14. model = Instance.new("Model",workspace)
  15. command("bots", function(number)
  16.     bots = { }
  17.     for i = 1, tonumber(number) do
  18.         local blocks = Instance.new("Part",model)
  19.         blocks.Size = Vector3.new(1,1,1)
  20.         blocks.Color = Color3.fromRGB(0, 0, 0)
  21.         blocks.CFrame = owner.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-5)
  22.         AgentRadius = tonumber(blocks.Size.Z)
  23.         AgentHeight = tonumber(blocks.Size.Y)
  24.         table.insert(bots,blocks)
  25.         end
  26. end)
  27. command("target", function(obj)
  28.     if game.Workspace[obj] ~= nil then
  29.         for i,v  in pairs(bots) do
  30.         function Pathf()
  31.             local pathFinder = game:GetService("PathfindingService")
  32.         while true do
  33.             wait()
  34.                     local path = pathFinder:CreatePath(AgentRadius,AgentHeight,false)
  35.                     if game.Workspace[obj]:FindFirstChild("HumanoidRootPart") then
  36.                         path:ComputeAsync(v.Position,game.Workspace[obj].HumanoidRootPart.Position)
  37.                     else
  38.                         path:ComputeAsync(v.Position,game.Workspace[obj].Position)
  39.                     end
  40.                        
  41.             if path.Status == Enum.PathStatus.Success then
  42.             else
  43.                 print("Trying again")
  44.                 return Pathf()
  45.             end
  46.             local pathpoints = path:GetWaypoints()
  47.                     for j = 1,#pathpoints do
  48.                         for l = 0,1,.01 do
  49.                             wait(.01)
  50.                             v.Position = v.Position:Lerp(pathpoints[j].Position,l)
  51.                             wait()
  52.                         end
  53.                
  54.             end
  55.         end
  56.     end
  57.         spawn(Pathf)
  58.     end
  59. end
  60.    
  61.  
  62.    
  63. end)
  64. command("del_bots", function(numbah)
  65.     local blockbots = model:GetChildren()
  66.     for i = 1, tonumber(numbah) do
  67.         blockbots[i]:Destroy()
  68.     end
  69. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement