Modules don't update

Whenever I create a module, while it is open in script editor and edit the entire code from something that would return an error, for example to something as simple as:

   local module = {}

   function module.add(...)
            local sum = 0
            for _, n in ipairs({...}) do
               sum += n -- combined op included in edit
            end
       return sum
   end

  return module

and then require it through the command bar while I am in script editor (and even when I am not) it just returns the previous error instead of running the the new , updated module’s code.

Why?
Do module scripts only update so their new code can be required only after you restart Studio or something?

This happens to me all the time. A solution I’ve found would be to cut the script onto your clipboard, and paste it back into it’s former parent. Then if you require the script via the command bar, it should work fine.

2 Likes

Modules only run once. Once you require them, the value is cached for the lifetime for the program. If you want to circumvent this, you can do require(your_module:Clone()) in the command bar instead of require(your_module).

11 Likes

Interesting. I did not know this happened in studio as well.

5 Likes