Oh sorry, I forgotten this.
It is a module script called from a script.
local agentPath = PathFindingService:CreatePath(pathParams)
agentPath:ComputeAsync(Freddy.PrimaryPart.Position, newPoint.Position)
if agentPath.Status == Enum.PathStatus.NoPath then print("No path") end
local Waypoints = agentPath:GetWaypoints()
for waypointIndex, waypoint in pairs(Waypoints) do
local choosedPlayer = canHunt()
if choosedPlayer then
--HuntModule:Start()
print(choosedPlayer.Name)
end
Agent.Humanoid:MoveTo(waypoint.Position)
Agent.Humanoid.MoveToFinished:Wait()
end
This Agent will chase a player if canHunt() returns a player
Let me just change a few things so the code looks more clean:
local agentPath = PathFindingService:CreatePath(pathParams)
agentPath:ComputeAsync(Freddy.PrimaryPart.Position, newPoint.Position)
if agentPath.Status == Enum.PathStatus.Success then
local Waypoints = agentPath:GetWaypoints()
for i, waypoint in ipairs(Waypoints) do
local chosenPlayer = canHunt()
if chosenPlayer then
-- hunt
print(chosenPlayer.Name)
end
Agent.Humanoid:MoveTo(waypoint.Position)
local moveSuccess = Agent.Humanoid.MoveToFinished:Wait(1)
-- if not moveSuccess then
--break (This is a check to see if the agent has truly successfully reached the next waypoint.)
--end
end
else
print("No path!")
end