Module script is only able to run one function (in studio...?)

local module = {}

function module.goToLocation(location)
	workspace.Camera.CFrame = workspace.Locations[location].TeleportPosition.CFrame

function module.goToLocation2(location)
	workspace.Camera.CFrame = workspace.Locations[location].TeleportPosition.CFrame

return module

each function’s code is the exact same, word for word, letter for letter, but only the top one works. why?

What is the error that is returned?

I think you also need to set the CameraSubject otherwise it goes straight back to the original CameraSubject.

i just told you the top one works. you are foolish. your tongue has tasted sour grapes.

strangely enough, it works ingame, but not in studio where im using it to get around locations quicker

i run it from the command bar while testing and it works fine, but running it from the command bar otherwise and i get this error


chill out :sweat_smile:

Anyway even if the top one works I had a similar issue where the camera sometimes moved and sometimes didn’t and it was fixed by the exact thing I suggested.

Can you send the script you are calling the module procedures from?

module scripts dont really work when used from the command bar, if you edit the module after already requiring it in the command bar it wont update and any function you added will not be accessible, even if you re-require it

guess this is a bug report now! has somebody posted about this before? id really like to make this known so it can be fixed

if anyone has the same problem as me the solution i have right now is to just duplicate the script everytime i update it

This is correct. If you want to run ModuleScript static code from the command line, you have to use require(moduleScript:Clone()) each time, to get a fresh copy, because for each copy the code runs just once per Studio session.

It’s not a bug though, it’s intended behavior that ModuleScripts only run once per VM instance and cache their return value. If the behavior was changed to automatically duplicate the module, it would mean you could no longer use variables in the scope of the module to hold state, which would make modules work differently from the command bar than everywhere else, which is even worse.

this was reported all the way back in 2014

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.