Will this cause lag and is there a way to optimise it?

Well basically I’m working on a fighting system, its literally done, but theres a small issue, so I inserted a script inside a string value inside an npc which whenever i hit, this string value will change to the player name and then the bot will follow this specefic player’s character and if it went too far away from the original position it will retreat, all this works perfectly fine although i’m running this on a while loop and I will obviously have many bots in the original game which means many while loops and i’m really scared from the lag it could cause.

Now many of you will say just use a local script but then I would need to fire a remote event each time i’m playing the animation, hitting, etc and that would be pretty much exploitable, would I need to leave it a while loop in a server script or is there a way to optimise it or does it even cause any lag in the first place?

1 Like

loops can not cause lag
it is what is contained in the loops that can cause lag

just make sure you have yielding in the loop and just try not to run heavy code in the loop

you should be completely fine tho

1 Like

Alrighty, thanks just making sure honestly thought multiple loops running at the same time could cause lag even if its not a heavy code

np, I hope your game turns out great after you get it public

1 Like