I am trying to use the script provided in the Roblox article about pathfinding to move a character from its current position to a part. However, upon clicking play, the character moves to my character’s position and stops. I’m perplexed because the script doesn’t make any references to other characters.
local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local path = PathfindingService:CreatePath()
local character = script.Parent
local humanoid = script.Parent:FindFirstChild("Humanoid")
local Destination = Vector3.new(game.Workspace.Endpoint.Position)
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
local function followPath(destination)
local success, errorMessage = pcall(function()
path:ComputeAsync(character.PrimaryPart.Position, destination)
end)
if success and path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", errorMessage)
end
end
followPath(Destination)