NPC can't reach player no matter how fast I set its speed

I am creating an enemy for my Backrooms Game, and while everything has been working so far, progress has come to a screeching halt for three days now as I have tried to fix this problem.

So, basically, I have a whole pathfinding script for the enemy to track you down. Here is the problem, when it gets close the the player, it just cant reach it when the player is moving, no matter how fast it is. I believe this is because the enemy reaches its walkto point before it can set another, causing it to stay just out of reach from the Player.

Yes, I have created a separate loop which runs if the enemy is close to the player, and yes, I have tested to make sure it is actually running this loop. I have been searching up fixes for three days now and have made very slow progress. I have set all parts/unions server ownership whatever to nil, and basically anything you can find for this online. I was wondering if anybody knew any good fixes for this.

robloxapp-20220304-1931578.wmv (2.2 MB)

spawn(function()
	while wait() do
		if WalkingThreadOveride then
			entity.Humanoid:MoveTo(WalkingThreadOveride.CFrame.Position)
		end
	end
end)

Thanks for taking the time to read through this!

1 Like

Maybe you can have it try to reach where the player is moving towards rather than the player themself. By reading the Player’s Character’s Humanoid’s MoveDirection (and converting it to worldspace) you can make the enemy walk towards there instead, so it’ll attempt to walk through the player rather than to it. If this doesn’t work fully first, try multiplying the distance from the player the MoveDirection is.

1 Like

Try setting your enemy model’s Network Ownership to nil.
As the enemy gets near you, its network ownership may constantly swap between the server and the player as it gets near, causing it to stutter whenever it gets near the player (and therefore swapping back to server since it’s far from the player again, and back to the player again, and on and on…) .

EnemyModel.PrimaryPart:SetNetworkOwner(nil)

If this fails, I would try making the enemy persuit the player’s position + their humanoid move direction * 4 or so to try to predict where the player is going.

2 Likes