Pathfinding AI sits and doesn't move

Hello.

I’ve been trying to fix this with my AI for a long time and it’s because of this issue.

When the AI is chasing a player and the player goes behind an obstacle, the AI takes 5+ seconds to create a path and follow it.

When the player goes into the Damaged Safe Shelter, (a building in the game that tricks players that it’s safe) the AI stops moving and sits there, constantly spamming the scream function that i added for when he first SPOTS the player.

Any help here would be appreciated.

Video:

You need to change it so that it can only scream once.
Then as for your pathfinding. Try to create a ray between the player and the AI.
If the ray is not blocked then just use :MoveTo()

If it is blocked then use pathfinding.
Keep in mind that the longer the path the longer it will take to generate.

If they spawn in a set location why not create a path and store it to get it inside the map, this means that when it first comes in it will be quick. Once inside the map pathfinding should take a lot less time as the distance wont be so great.

MoveTo gives up after so many seconds and there’s no way to change the internal behavior of the function, if I’m not mistaken, so that might be your problem

Posting your code would help, though

For it to chase without pathfinding. this code is put in the pathfinding function to avoid mixups

if seetarget(target) then
			repeat
				hum:MoveTo(target.Position)
				if (humroot.Position - target.Position).magnitude < 10 then 
					attack(target)
					print("attacking")
				
				end
				fastWait()
				if target == nil then
					break
				elseif target.Parent == nil then
					break
				end
			until seetarget(target) == false or hum.Health < 1 or target.Parent.Humanoid.Health < 1
			break
		end