Requested Module experienced an error while loading issue

so I use a module and a local script for a tower spawning and attacking system. Now I decided to use the module inside the local script for OOP (Object Oriented Programming) so I can transfer certain values from the module to the local script.

Now doing this prompted me with 2 errors:


For some reason, the module starting running on the client (I’m guessing that’s the issue), now this wasn’t a problem before and it pretty much fixes itself if I just don’t require the module but I pretty much need the module for this.

Does anyone know what I can do?

1 Like

The error you’re seeing is pretty straightforward: you’re trying to setup a OnServerEvent connection on a ModuleScript being invoked by the client.

Modules cannot execute their own code. If you require the module on the client, it will run on the client. This is causing your issue when you attempt to connect OnServerEvent on the client.

1 Like

hm, what can I do about this? I already require the module on the server as well

If you NEED the module on both sides, wrap the OnServerEvent code with

if RunService:IsServer() then
    ...
end

However I’d personally say this is bad practice, I’d never had to deal with something like this, so consider this a temporary solution.

2 Likes

this seemed to work, thank you!

I’d recommend removing any server-only code, basically holding two different copies. Be careful, if you leave server only code in the client module, exploiters could decompile it and look for weak points in your code, making it exploitable and they may be able to force errors server-side, causing issues.

I’m only sending visual information from a configuration table in my module. Not anything game breaking on the client,

1 Like

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