Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Requiring a module script more than once?

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

3 comments

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

0

Sorry I was unclear, for example if I had a while wait loop inside, if I require twice will the loop run twice?

0

Attempting to require a module script more than once, the result is cached.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.