Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ServerScript inside a MainModule is not running his code?

Ok, so I asked this question a few days ago but no one seemed to really help me. So I am asking it again in the hope someone will finnaly help me.

So I got a script called Loader this is a ServerScript and it's requiring my MainModule. And yes! I have uploaded the MainModule to ROBLOX, so that's not the problem. Ok, so the Loader Script does his work.

The code of the MainModule is:

print("MainModule loaded!")

return true

So now you're asking what's the problem? Well, the MainModule is not the problem. I got a ServerScript inside the MainModule and the code of that ServerScript never runs... Lets call it PrintScript just to make is more clear. So it's like: MainModule > PrintScript. (because the PrintScript is inside of the MainModule.)

PrintScript code:

print(script.Name.." ran!") -- Never happens?!?

The PrintScript isn't disabled so that's not the problem! So, the problem is that PrintScript never runs.

Important notes: My game is FilteringEnabled.

Does anyone know how to fix this so the PrintScript runs his code? Thank you for your time. And I hope you can help me.

1 comment

0

Is this all the code from PrintScript? Also, where are the scripts located, what is the importance of mainmodule, and where/how are you requireing it?

1 answer

✓ Accepted answer

Your PrintScript isn't running because it's not a descendant of any object that it can run within. When you require() your asset it is creating a hierarchy of <nil>.Model.MainModule.PrintScript. A ServerScript should be run within Workspace or ServerScriptService.

Now there are a few ways of making your PrintScript work. The simplest would be to set PrintScript's Parent from your MainModule.

print("MainModule loaded!")
script.PrintScript.Parent = game:GetService("ServerScriptService")
return true

Another way is to turn your PrintScript into a ModuleScript and require it from the MainModule.

print("MainModule loaded!")
require(script.PrintScript)
return true

1 comment

0

It's at least doing something now, so thank you for that. - Accept answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.