Problem with requiring ModuleScripts in ServerScriptService

Hello!

Im currently working on a very small Game Framework for my game similar to the one by @berezaa for Vesteria and im running into an error and i don´t know how to fix it.

    for i, moduleScript in pairs(directory:GetDescendants()) do
        if moduleScript:IsA("ModuleScript") then
           
            local requireModule = require(moduleScript)
            modules[moduleScript.Name] = requireModule

            debug:print("$Main Server: added Module " .. moduleScript.Name)
         end
    end

directory is a location from the table below.
I have a table with all locations of the modules i want to require.

local directories = {ReplicatedStorage.modules, ServerScriptService.contents}

When I remove the ServerScriptService.contents everything works just as expected!
BUT, when i don´t remove the ServerScriptService.contents the following error gets printed

18:24:45.136  Requested module experienced an error while loading  -  Server - server_test:20
  18:24:45.136  Stack Begin  -  Studio
  18:24:45.136  Script 'ServerScriptService.server_test', Line 20 - function setup  -  Studio - server_test:20
  18:24:45.136  Script 'ServerScriptService.server_test', Line 39  -  Studio - server_test:39

I think the problem is that the module is getting add when loading the game but not fully loaded while I am already requiring it.

I already tried ContentProvider:PreloadAsync() but it didn´t change anything and the error was still apearing!

I hope you have some ideas or even the Solution for this Problem.
Thanks!

@TheHeroGamer001

The error the module had should be listed directly above the “requested module experienced an error” error

It seems like a module script you have in ServerScriptService.contents is erroring when it is being required. Try printing the name of the module before you require it and you can figure out where the error is coming from by the last-printed message

9 Likes

Thanks!
It actually was a Module that caused the error. I didn’t find the part where the error came from but It was only a module for testing Server-Client so i was ablento delete it without rewriting it.