local Molly = script.Parent
local humanoid = Molly.Humanoid
local PathfinderServise = game:GetService("PathfindingService")
local function getPath(destination)
local pathParams = {
['AgentHeight'] = 6,
['AgentRadius'] = 2,
['AgentCanJump'] = false
}
local path = PathfinderServise:CreatePath(pathParams)
path:ComputeAsync(Molly.HumanoidRootPart.Position, destination.Position)
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:GetChildren()
local randomNum = math.random(1, #waypoints)
walkTo(waypoints[randomNum])
end
while wait(2) do
patrol()
end