Any Fixes or Alternatives to pathfindingservice?

Is it me or does pathfindingservice cause memory leaks and lag?
i believe that i can’t really fix this problem with enemy AI in my game

I’ve tried reducing the computing interval, creating the path object once, destroying the path object when it’s not needed anymore, dereferencing the object. Server Performance problems still persist and are very severe. when about 12 enemies are on the map, the server fps goes down to 20 fps or even 5 in some cases

Memory leaks caused by AI


Lag caused by AI

1 Like

Try using simple path. It’s a path finding module. Search it up. :smile:

simple path uses pathfinding service
i’m afraid of using that because the service is what causes the problems from what i understand

Simple path is really laggy and buggy, also the author doesn’t care much for it anymore. PathfindingService doesn’t make memory leaks, so I’m afraid it’s your code

1 Like

If your trying to make really smart ai. For a bot that is just a very common enemy its not worth doing. The reason why horror games have very complicated bots is because there is only one of them.

1 Like

Looks like,

local rns=game:GetService(“RunService”)
rns.Stepped:Wait()

,Is not a part of your scripts.

1 Like

Memory leaks are most likely due to unkept loops. So if you keep your loops at check it should be fine. What game are you trying to make exactly?

i use task.wait in my loops and not runservice, isn’t it the same thing?

i want them to be able to pathfind their way to the target and not be dumb so i figured i had to use pathfinding

1 Like

a game about defending a base from waves of enemies
I’m pretty sure the loops stop when the enemy for instance, dies
https://create.roblox.com/dashboard/creations/store/16180249330 the actual ai script is here
Plus the way the memory leaks presents itself is it will after a random amount of time, usually 10 minutes spike up from 1,000 megabytes to 2000 in an instant

Not really … stepped adjusts itself with the flow rate. It’s like an assemblers top of frame pause. It adjusts with the frames per second.

from what i saw, task.wait does the same thing
if flow rate is 10 fps than task.wait will be equal to .1 seconds

Without any code to check, there’s no way to say what the exact problem is. If you could upload the code here or a place demo file we’d probably give you better feedback. Otherwise it’s just guessing and checking.

The link you gave is a private link. We cannot see it or access it.

task.wait is absolute … needed or not. treebee63 is right. Hard to say anything really but speculation without that.

what does “absolute” mean in that situation?

Oops, i will update the link https://create.roblox.com/store/asset/16180249330/Smart-AI

I tested it in an empty baseplate and I did see some memory climbing (untracked memory), this is with using 12 AIs and letting them run for 5 minutes.

Start of test:
image

After 5 minutes:
image

I noticed your code pattern doesn’t assume that some variables could be existing before a reference overwrite, such as this connection here:

If BlockConn existed when you set it to a new value, you’ve suddenly created 2 events on the same path.

I went ahead and patched it.

Start game.
image

After 5 minutes.
image

Conclusion: Looks like it fixed it, but check your code and make sure no other coding pattern like that exists. Good luck!

untracked memory here says 307 mb
i don’t know if that really fixed it

Are you repeating using the exact setup as you had in the original post? Is the problem still there when you’re in-game and looking at the metrics?

i’ll test the current solution you provided
also i suggest you make the map 4096 studs in width and you’ll see the full effect