Hi, so I don’t get this issue whilst in studio but the NPC seems to get stuck and almost chug along when the checkpoint is reached, any way to solve this or any Modules I could use instead of this?
Module Code
local module = {}
function module.Move(Nill, Part, Humanoid)
print(Part.Name)
local Touched = false
local PathfindingService = game:GetService('PathfindingService')
local path = PathfindingService:CreatePath()
-- Compute the path
path:ComputeAsync(Humanoid.Parent.HumanoidRootPart.Position, Part.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex
local function followPath(destinationObject)
-- Compute and check the path
path:ComputeAsync(Humanoid.Parent.HumanoidRootPart.Position, Part.Position)
-- Empty waypoints table after each new path computation
waypoints = {}
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start zombie walking
waypoints = path:GetWaypoints()
-- Move to first waypoint
currentWaypointIndex = 1
Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
return true
else
-- Error (path not found); stop humanoid
Humanoid:MoveTo(Humanoid.Parent.HumanoidRootPart.Position)
end
end
local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
Humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
print(Part.Name .. ' 1')
end
end
local function onPathBlocked(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex > currentWaypointIndex then
-- Call function to re-compute the path
followPath(Part)
end
end
-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)
-- Connect 'MoveToFinished' event to the 'onWaypointReached' function
Humanoid.MoveToFinished:Connect(onWaypointReached)
if Touched == false then
Part.Touched:Connect(function()
if Touched == false then
Touched = true
end
end)
end
followPath(Part)
repeat wait() until Touched == true
return true
end
return module