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.
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.
For it to chase without pathfinding. this code is put in the pathfinding function to avoid mixups
if seetarget(target) then
if (humroot.Position - target.Position).magnitude < 10 then
if target == nil then
elseif target.Parent == nil then
until seetarget(target) == false or hum.Health < 1 or target.Parent.Humanoid.Health < 1