I am creating a restaurant game were people get customers that are their friends running from the client. I am new to pathfinding, so I have been following this guide. However, the guide is confusing me even more, and trying to follow it the code is not working now that I am at the end.
The code has an if statement, and it checks if path.Status == Enum.PathStatus.Success however it is not running because the path.Status is Enum.PathStatus.NoPath
Is there a reason that this is happening? I have tried putting vector3.new() around the seats position but it's still not working.
The code [Only the pathfinding part, as I dont believe any other piece is needed.]:
local Target = Mouse.Target
Target = Target.Parent.Parent
print(Target)
if Target:FindFirstChild("Amount") then
local Seat = Target:FindFirstChild("Seat",true)
print(Seat)
local currentWaypointIdx = 1
local PathSettings = {
AgentRadius = 3.0,
AgentHeight = 0.0,
AgentCanJump = false,
}
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local path = PathService:CreatePath(PathSettings)
local function followPath(destination)
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(Customer.PrimaryPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
-- Get the path waypoints
waypoints = path:GetWaypoints()
-- Detect if path becomes blocked
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex >= nextWaypointIndex then
-- Stop detecting path blockage until path is re-computed
blockedConnection:Disconnect()
-- Call function to re-compute new path
followPath(destination)
end
end)
-- Detect when movement to next waypoint is complete
if not reachedConnection then
reachedConnection = Humanoid.MoveToFinished:Connect(function(reached)
print("B")
if reached and nextWaypointIndex < #waypoints then
-- Increase waypoint index and move to next waypoint
nextWaypointIndex += 1
Humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
-- Initially move to second waypoint (first waypoint is path start; skip it)
nextWaypointIndex = 2
print("A")
Humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", success, path.Status, errorMessage)
end
end
followPath(Vector3.new(Seat.Position))
print("Yes")
Clicked:Disconnect()
end
The line warn("Path not computed!", success, path.Status, errorMessage) gives: Path not computed! true Enum.PathStatus.NoPath nil
