For my game, I have a pathfinding NPC that works fine until it stands still for too long, then it starts to look like it starts to go on and off making it look like it is limping, I have tried teleporting it and even leaving the script disabled bedore re-enabling it, do I have to teleport another npc in it's place to stop it from doing this?
Code:
Pathfinding:
-- script is placed inside a movable NPC model
-- get pathfinding service
local pathfindingService = game:GetService("PathfindingService")
-- Variables for NPC humanoid, torso, and destination
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Wilson.Destination.Position
-- create path object
local path = pathfindingService:CreatePath()
-- compute a path
path:ComputeAsync(body.Position, destination)
-- get the waypoints table
local waypoints = path:GetWaypoints()
-- iterate through all waypoints, and jump when necessary
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
-- change humanoid state to jump if necessary
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end
How I make the character move to a different location: (after changing the CFrame of the destination brick)
game.Workspace.Wilson.WilsonAI.Pathfind.Disabled = true
wait(0.1)
game.Workspace.Wilson.WilsonAI.Pathfind.Disabled = false

1 comment
Do you think there is a way to fix it? Like cloning it into the bot each time?