Sir_Spaceboi

jason npc thing

Sep 18th, 2021
729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local PathfindingService = game:GetService("PathfindingService")
  2. local CustomerFolder = game.ReplicatedStorage.Customers
  3. local SpawnsFolder = workspace.NPCSpawns
  4.  
  5. -- Get the random NPC
  6. local children = CustomerFolder:GetChildren()
  7. local random_customer = children[math.random(1, #children)]
  8.  
  9. -- Find a spawn for it
  10. local spawns = SpawnsFolder:GetChildren()
  11. local random_spawn = spawns[math.random(#spawns)]
  12.  
  13. -- Variables
  14. local npc = game.ReplicatedStorage.Customers:FindFirstChild(random_customer.Name)
  15. local npcClone = npc:Clone()
  16. npcClone.Parent = workspace
  17. npcClone:SetPrimaryPartCFrame(random_spawn.CFrame)
  18.  
  19. local humanoid = npcClone.Humanoid
  20. local root = npcClone.HumanoidRootPart
  21. local destination = game.Workspace:WaitForChild("Register" .. 1).Region3Zone
  22. local waitPart = game.Workspace:WaitForChild("NPCWaitPart")
  23.  
  24. -- Create the path object
  25. local path = PathfindingService:CreatePath()
  26. local path2 = PathfindingService:CreatePath()
  27.  
  28. -- Table of Orders
  29. local PossibleOrders = {
  30.     "Watermelon Smoothie with a Vanilla Ice cream",
  31.     "Strawberry Ice cream with Sprinkles",
  32.     "Large Latte and a Cookie Dough Ice cream"
  33. }
  34.  
  35. -- Compute the path
  36. path:ComputeAsync(npcClone.HumanoidRootPart.Position, destination.Position)
  37. path2:ComputeAsync(npcClone.HumanoidRootPart.Position, waitPart.Position)
  38.  
  39. -- Get the path waypoints
  40. local waypoints = path:GetWaypoints()
  41. local waypoints2 = path2:GetWaypoints()
  42. print(waypoints)
  43.  
  44. -- Optimize the NPC movement
  45. for index, item in pairs(npcClone:GetChildren()) do
  46.     if item:IsA("BasePart") then
  47.         item:SetNetworkOwner(nil)
  48.     end
  49. end
  50.  
  51. --
  52.  
  53. if path.Status == Enum.PathStatus.Success then
  54.     for _, waypoint in pairs(waypoints) do 
  55.         if waypoint.Action == Enum.PathWaypointAction.Jump then
  56.             humanoid.Jump = true
  57.         end
  58.         humanoid:MoveTo(waypoint.Position)
  59.         delay(0.5, function()
  60.             if humanoid.WalkToPoint.Y > root.Position.Y then
  61.                 humanoid.Jump = true
  62.             end
  63.         end)
  64.         humanoid.MoveToFinished:Wait()
  65.     end
  66. else
  67.     print("Path didn't come out right!")
  68. end
RAW Paste Data