local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local path
local function GetPath(destination)
local pathParams = {
AgentCanJump = true,
AgentHeight = 5,
AgentRadius = 2,
--Costs = {DangerZone = 20, UseCrosswalk = 2}
}
path = path or PathfindingService:CreatePath(pathParams)
local success, errorMessage = pcall(function()
path:ComputeAsync(character.PrimaryPart.Position, destination.Position)
end)
return path
end
local function walkTo(destination)
local path = GetPath(destination)
for index, waypoint in pairs(path:GetWaypoints()) do
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
end
local function Patrol()
local waypoints = workspace.City.TestWaypoints:GetChildren()
local waypoint = math.random(1, #waypoints)
walkTo(waypoints[waypoint])
end
while true do
Patrol()
wait(2)
end
character.HumanoidRootPart:SetNetworkOwner(nil)