Help increase script performance (NPCs and loops)

I’ve been creating a group game with many scripts and loops, as the game gets more complex, the waits become less exact and slow and replacing all the waits with task.wait just makes the game very laggy and low fps. After restoring a backup I’m unsure of what to do to improve performance. My game includes many NPCs, some environmental and some realistic mechanics but I don’t really want to give too much detail about the game to keep it mostly private until finally done or such.


What kind of scripts does the game have mainly? Npcs may be an area where performance losses may appear but that does depend a lot. Not entirely sure what you mean with the environmental and realistic things however.


I’ve haven’t done much in the map yet since I’ve been mostly working on scripts mainly npcs to get it right but it made things slow down. I’ve notice some for loops cause slow downs when going through all descendants so I went with :getchildren instead but i’m not too sure what alternatives could be when having npcs search for their “objective” like jobs or activities. Also trying to make it flexible so I could easily create new areas for the same thing or such.

1 Like

Do you mean to say that the for loops go through all the workspace instances? In that case, you should start using tags instead.


Probably a better option since it would be much faster but would probably take awhile to setup CollectionService | Documentation - Roblox Creator Hub

Write a script or repurpose your current one, then make it add tags to the parts you need. And then run the script in the console or with the run script ribbon bar button.

1 Like

Yeah, but I have a lot of scripts to go through before I’ll start noticing a difference but thank you I’ll try it in a couple mins after dinner.

I’ve replaced many for loops to search tags instead of workspace and started noticing a increased performance but waits are still not exact though. Any more suggestions?

Open the microprofiler with ctrl + alt + f6, then you can see individual frames by hitting ctrl + p. This will allow you to see what’s taking up all of your frame time, whether it be roblox internal systems or your scripts. I’m assuming you don’t have an insanely massive/detailed map so its probably your scripts causing all the lag, and with this you should be able to see what processes are taking up all of the frame time, and optimize from there.

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