Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PathfindingService = game:GetService("PathfindingService")
- local CustomerFolder = game.ReplicatedStorage.Customers
- local SpawnsFolder = workspace.NPCSpawns
- -- 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)]
- -- Variables
- local npc = game.ReplicatedStorage.Customers:FindFirstChild(random_customer.Name)
- local npcClone = npc:Clone()
- npcClone.Parent = workspace
- npcClone:SetPrimaryPartCFrame(random_spawn.CFrame)
- local humanoid = npcClone.Humanoid
- local root = npcClone.HumanoidRootPart
- local destination = game.Workspace:WaitForChild("Register" .. 1).Region3Zone
- local waitPart = game.Workspace:WaitForChild("NPCWaitPart")
- -- 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)
- path2:ComputeAsync(npcClone.HumanoidRootPart.Position, waitPart.Position)
- -- Get the path waypoints
- local waypoints = path:GetWaypoints()
- local waypoints2 = path2:GetWaypoints()
- print(waypoints)
- -- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement