Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Requiring a module script more than once?

Asked by
trecept 367 Moderation Voter
5 years ago

If I have a changed function inside a module script and I require it twice, will the changed function run twice or once?

1
How would you change a function in it after requiring it though? If you mean overrieing a function with getfenv() then the answer is no, it wont run twice Amiaa16 3227 — 5y
0
Sorry I was unclear, for example if I had a while wait loop inside, if I require twice will the loop run twice? trecept 367 — 5y
0
Attempting to require a module script more than once, the result is cached. User#24403 69 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

See the documentation for ModuleScript.

A ModuleScript is a type of Lua source container that runs once and must return exactly one value. This value is then returned by a call to require given the ModuleScript as the only argument. ModuleScripts run once and only once per Lua environment and return the exact same value for subsequent calls to require.

Ad

Answer this question