Sir_Spaceboi

npc script n

Dec 11th, 2021
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. local function Code()
  2. warn(script.Name .. " | Starting")
  3. local PathfindingService = game:GetService("PathfindingService")
  4. local CustomerFolder = game.ReplicatedStorage.NPCs
  5. local SpawnsFolder = workspace.NPC.Spawns
  6. local locationsFolder = workspace.NPC.Locations
  7.  
  8. while true do
  9. -- Get the random NPC
  10. local children = CustomerFolder:GetChildren()
  11. local random_customer = children[math.random(1, #children)]
  12.  
  13. -- Find a spawn for it
  14. local spawns = SpawnsFolder:GetChildren()
  15. local random_spawn = spawns[math.random(#spawns)]
  16.  
  17. -- Calculate a random destination
  18. local locations = locationsFolder:GetChildren()
  19. local random_location = locations[math.random(#locations)]
  20.  
  21. -- Variables
  22. local npc = CustomerFolder:FindFirstChild(random_customer.Name)
  23.  
  24. local npcClone = npc:Clone()
  25. warn("NPC Inserted | Name: " .. npcClone.Name)
  26.  
  27. npcClone.Parent = workspace.NPC.NPCs
  28. npcClone:SetPrimaryPartCFrame(random_spawn.CFrame)
  29.  
  30. local humanoid = npcClone.Humanoid
  31. local root = npcClone.HumanoidRootPart
  32.  
  33. local destination = random_location
  34.  
  35. -- Create the path object
  36. local path = PathfindingService:CreatePath()
  37. local path2 = PathfindingService:CreatePath()
  38.  
  39. -- Table of Orders
  40. local PossibleOrders = {
  41. "Watermelon Smoothie with a Vanilla Ice cream",
  42. "Strawberry Ice cream with Sprinkles",
  43. "Large Latte and a Cookie Dough Ice cream"
  44. }
  45.  
  46. -- Compute the path
  47. path:ComputeAsync(npcClone.HumanoidRootPart.Position, destination.Position)
  48.  
  49. -- Get the path waypoints
  50. local waypoints = path:GetWaypoints()
  51. local waypoints2 = path2:GetWaypoints()
  52.  
  53. -- Optimize the NPC movement
  54. for index, item in pairs(npcClone:GetChildren()) do
  55. if item:IsA("BasePart") then
  56. item:SetNetworkOwner(nil)
  57. end
  58. end
  59.  
  60. --
  61.  
  62. path.Blocked:Connect(function()
  63. path:ComputeAsync(npcClone.HumanoidRootPart.Position, destination.Position)
  64.  
  65. if path.Status == Enum.PathStatus.Success then
  66. for _, waypoint in pairs(waypoints) do
  67. if waypoint.Action == Enum.PathWaypointAction.Jump then
  68. humanoid.Jump = true
  69. end
  70. humanoid:MoveTo(waypoint.Position)
  71. delay(0.5, function()
  72. if humanoid.WalkToPoint.Y > root.Position.Y then
  73. humanoid.Jump = true
  74. end
  75. end)
  76. humanoid.MoveToFinished:Wait()
  77. end
  78. else
  79. print("Path didn't come out right!")
  80. end
  81. end)
  82.  
  83. if path.Status == Enum.PathStatus.Success then
  84. for _, waypoint in pairs(waypoints) do
  85. if waypoint.Action == Enum.PathWaypointAction.Jump then
  86. humanoid.Jump = true
  87. end
  88. humanoid:MoveTo(waypoint.Position)
  89. delay(0.5, function()
  90. if humanoid.WalkToPoint.Y > root.Position.Y then
  91. humanoid.Jump = true
  92. end
  93. end)
  94. humanoid.MoveToFinished:Wait()
  95. end
  96. else
  97. print("Path didn't come out right!")
  98. end
  99. wait(35)
  100. end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment