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

Issues calling a ModularScript?

Asked by 4 years ago

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?

0
See if you accidentally left a whitespace character within the Name of the ModuleScript? Ziffixture 6913 — 4y

2 answers

Log in to vote
0
Answered by
kisty1 111
4 years ago
Edited 4 years ago

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

0
I will give this a go next time I'm on, sounds like it has promise though! And thanks for the tip about storage :) AlexTheCreator 461 — 4y
0
No problem :) kisty1 111 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

0
I am using the module script as storage for functions I use often so I dont have to repeat my code. Is that an appropriate use? AlexTheCreator 461 — 4y
0
Yes and the intended use. Simply place the module in ReplicatedStorage and update the code to point to that location and everything will work. (keep the wait for child as things take time to load in the client side) User#5423 17 — 4y

Answer this question