Hi all im getting this error when calling a ModularScript from a local script and I'm not sure why...
Infinite yield possible on 'ServerScriptService:WaitForChild("guiModularScript")
If i put :WaitForChild("guiModularScript", 1) ... which I thought was the correct way to give a timeout but I'm given "Attempted to call require with invalid argument(s)" instead.
Can anyone tell me what's going wrong here?
I assume you're doing this
local module = require(ServerScriptService:WaitForChild("guiModularScript", 1))
If the module script does not appear within 1 second, WaitForChild just returns nil, which is then fed into require, and that is the reason it throws an error Do this instead
local ModuleScript = ServerScriptService:WaitForChild("guiModularScript", 1) if ModuleScript then -- ... end
One more thing is, You can't get any instances in ServerScriptService / ServerStorage from a local script. Place the module script inside ReplicatedStorage instead
The contense of ServerScriptService
will never replicate to the client. By definition why you are trying to achieve is impossible.
If you wish to share the same module script (this is a copy of) then place it in a more appropriate location e.g. ReplicatedStorage.
Another thing to note is that modules will run in the enviroment they are called e.g. local script / server script. Lastly a module is not a replacement for remote events / functions each device will have its own copy of the module script running on the device.
I hope this helps. Please comment if you have any other questions related to this.