Do module scripts cause more lag then code?

So I have a system which uses module script. A certain function has to use 2 of these module scripts. I was wondering if these module scripts would cause more lag, less lag, or equal amount of time as multiple line script in a server script.

2 Likes

Don’t worry about lag. Especially for something small as this. TL;DR no. Modules don’t cause lag. Poor implementations can though.

4 Likes

Modules only run once on the first require() (server and client are separate) after that it just returns a cached value on subsequent require()s

It may technically be slightly slower(I think) because you have to index a table to use the functions, but it would be so little that it doesn’t even matter

3 Likes

Code is code. A ModuleScript just provides you a different way of working with code following in the spirit of the lazy loading pattern (you can adopt eager loading patterns with ModuleScripts depending on the system you’re using). Using a ModuleScript or a regular script doesn’t define whether your game will lag or not, it is the content of your scripts altogether that you should be concerned about.

4 Likes