Module Scripts - When i shoud not use it

I want to open this discuss here about how to put less load on the processor.
I have one friend that uses a module script even in the simplest things that could be done in a normal script. My question is: it is more stressful for the processor use Module script or the normal script?

Anyone has made a stress test to see if what is better to use?

======================================
BEST ANWSERS:

  1. The stress on the processor won’t be that much of a difference. Anyways don’t use modules in the places you know you are only going to use once, or if the code is just 1 - 3 lines

  2. module scripts run on the normal scripts, so it would only slow you down a bit when trying to reference and require it
    it’s pretty negligible

1 Like

I don’t really believe there is going to be a significant difference of stress on the processor with module scripts and scripts, since if there was there’d be huge problems. It’s also hard to compare the two since they both do different things. As far as performance goes, there’ll be no noticeable problems, and even still if there were, moduleScripts are still good assets.

1 Like

The stress on the processor won’t be that much of a difference. Anyways don’t use modules in the places you know you are only going to use once, or if the code is just 1 - 3 lines

You should not use module scripts when using services or data stores or anything that includes local.
According to Roblox, module scripts can’t have local in it.
Here is a doc that will give you information of when to use it

2 Likes

module scripts run on the normal scripts, so it would only slow you down a bit when trying to reference and require it
it’s pretty negligible

the only time I wouldnt use a module script is when the module returns a value that must change each time it’s requested

e.g. a module script gets the time once, then always returns the same number

-- the module script
return os.clock()

-- the script
print( require(moduleScript) )
wait()
print( require(moduleScript) )

also, I was bored and just tried. a module script that’s about 180kB took 0.01 seconds to require 1e5 times (because of caching too)
it’s really negligible

1 Like

they can have local values
you just can’t access local variables outside of its scope

2 Likes

That’s incorrect; you absolutely can use ModuleScripts for services and DataStores. I don’t know what you mean by “local” (assuming local variables), but you can also use local variables.

This explicitly says that if you’re planning to use something outside of the ModuleScript, don’t use local variables because local variables are only accessible within the scope of the script.

that part of the document is weird because it’s making it sound like you can use global variables from module scripts when you can’t

-- module script
a = 5

return 2

-- script that uses the module script
print( require(theModuleScript) ) -- prints 2
print(a) -- prints nil instead of 5

The performance costs for module scripts is very insignificant. Your actual programming will have way more of an effect than the performance costs of requiring a module script.