How to optimize a "while" loop

I would like to know how to optimize a “while” loop in the best way so I can use it repeatedly and not have to worry about it lagging my game. Thanks!

There really isn’t any one answer to that, because it all depends on what you are doing inside that while loop

Optimize the stuff inside the loop

And only do that if there’s actually a problem


Most of my games have a pathfinding script inside the while loop, which I know lags the game a lot. Maybe what I was trying to asking for was how to optimize a pathfinding script

Best thing to do is to check to see if the pathfinding property or variable is changed and if so then perform your code.

You don’t put pathfinding in a while loop. There are event handlers for that. Look at Roblox’s example code here.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.