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

ServerScript inside a MainModule is not running his code?

Asked by 8 years ago

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.

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? AwsomeSpongebob 350 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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
0
It's at least doing something now, so thank you for that. - Accept answer. manchester1002 57 — 8y
Ad

Answer this question