Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wait(2)
- local PathfindingService = game:GetService("PathfindingService")
- local CustomerFolder = game.ReplicatedStorage.NPCs
- local SpawnsFolder = workspace.NPC.Spawns
- local locationsFolder = workspace.NPC.Locations
- while true do
- -- Get the random NPC
- local children = CustomerFolder:GetChildren()
- local random_customer = children[math.random(1, #children)]
- -- Find a spawn for it
- local spawns = SpawnsFolder:GetChildren()
- local random_spawn = spawns[math.random(#spawns)]
- -- Calculate a random destination
- local locations = locationsFolder:GetChildren()
- local random_location = locations[math.random(#locations)]
- -- Variables
- local npc = CustomerFolder:FindFirstChild(random_customer.Name)
- local npcClone = npc:Clone()
- warn("NPC Inserted | Name: " .. npcClone.Name)
- npcClone.Parent = workspace.NPC.NPCs
- npcClone:SetPrimaryPartCFrame(random_spawn.CFrame)
- local humanoid = npcClone.Humanoid
- local root = npcClone.HumanoidRootPart
- local destination = random_location
- for _, NPC in pairs(workspace.NPC.NPCs:GetChildren()) do
- if NPC:FindFirstChild("Humanoid") then
- -- Optimize the NPC movement
- for index, item in pairs(NPC:GetChildren()) do
- if item:IsA("BasePart") then
- item:SetNetworkOwner(nil)
- end
- end
- local randomNum = math.random(0, 10)
- NPC.Patience.Value = NPC.Patience.Value + randomNum;
- if NPC.Patience.Value >= 10 then
- local leavePath = PathfindingService:CreatePath()
- leavePath:ComputeAsync(NPC.HumanoidRootPart.Position, workspace.NPC.LeaveDestination.Position);
- local waypoints = leavePath:GetWaypoints()
- if leavePath.Status == Enum.PathStatus.Success then
- for _, waypoint in pairs(waypoints) do
- if waypoint.Action == Enum.PathWaypointAction.Jump then
- humanoid.Jump = true
- end
- humanoid:MoveTo(waypoint.Position)
- delay(0.5, function()
- if humanoid.WalkToPoint.Y > NPC.HumanoidRootPart.Position.Y then
- humanoid.Jump = true
- end
- end)
- humanoid.MoveToFinished:Wait()
- end
- else
- print("Path didn't come out right!")
- end
- wait(5)
- NPC:Destroy()
- wait("NPC Removed | " .. NPC.Name)
- end
- local humanoid = NPC:WaitForChild("Humanoid")
- local randomLocation = locations[math.random(#locations)]
- local newPath = PathfindingService:CreatePath()
- newPath:ComputeAsync(NPC.HumanoidRootPart.Position, randomLocation.Position)
- local waypoints = newPath:GetWaypoints()
- if newPath.Status == Enum.PathStatus.Success then
- for _, waypoint in pairs(waypoints) do
- if waypoint.Action == Enum.PathWaypointAction.Jump then
- humanoid.Jump = true
- end
- humanoid:MoveTo(waypoint.Position)
- delay(0.5, function()
- if humanoid.WalkToPoint.Y > NPC.HumanoidRootPart.Position.Y then
- humanoid.Jump = true
- end
- end)
- humanoid.MoveToFinished:Wait()
- end
- else
- print("Path didn't come out right!")
- end
- end
- end
- -- Create the path object
- local path = PathfindingService:CreatePath()
- local path2 = PathfindingService:CreatePath()
- -- Table of Orders
- local PossibleOrders = {
- "Watermelon Smoothie with a Vanilla Ice cream",
- "Strawberry Ice cream with Sprinkles",
- "Large Latte and a Cookie Dough Ice cream"
- }
- -- Compute the path
- path:ComputeAsync(npcClone.HumanoidRootPart.Position, destination.Position)
- -- Get the path waypoints
- local waypoints = path:GetWaypoints()
- local waypoints2 = path2:GetWaypoints()
- -- Optimize the NPC movement
- for index, item in pairs(npcClone:GetChildren()) do
- if item:IsA("BasePart") then
- item:SetNetworkOwner(nil)
- end
- end
- --
- if path.Status == Enum.PathStatus.Success then
- for _, waypoint in pairs(waypoints) do
- if waypoint.Action == Enum.PathWaypointAction.Jump then
- humanoid.Jump = true
- end
- humanoid:MoveTo(waypoint.Position)
- delay(0.5, function()
- if humanoid.WalkToPoint.Y > root.Position.Y then
- humanoid.Jump = true
- end
- end)
- humanoid.MoveToFinished:Wait()
- end
- else
- print("Path didn't come out right!")
- end
- warn("NPCS | NPCs currently in game: ")
- for i,v in pairs(workspace.NPC.NPCs:GetChildren()) do
- print(v)
- end
- wait(35)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement