Modulescript not working when published!

Hey there!

I have recently came across an issue i’m facing,

Please note: I have read through the modulescripts docs I have made sure the Modulescript is name MainModule etc.

I have also used basic debugging to check the functions, for example print('1')

I have a module script that uses script.Disabled = true / false etc.

As you can see below the scripts.
image

The functions work they just don’t enable the scripts.

But if i require the model within the game, they work fine, but if i require the module out of the game none of the scripts enable, But functions within the module work.

Thank you if you can help!

why would you do that though.
just have an main script that calls modules scripts that handles what ever you want to do so you can call them whenever you want.

Hey @foundanerror! I’ve done this as it’s for multiple of people to use so I can update them / fix bugs amonst the loops etc, without them having to replace the asset.

I am confused about what you just said. Please explain further. You would able to do the exact thing you are trying to do with and modular architecture. Its way better for organizing and debuging your code trust me. I use to do the same thing you are doing now. If you need help maintaining that structure i recommend you try using knit as it helps maintain an modular flow. Knit | Knit

You can also try AGF made by the same person but knit is better as it adresses AGF problems and I haven’t tried it out myself. AeroGameFramework

Basically, the functions run. But within in the function it has script.Disabled = false. But yet it doesn’t enable the loop / script.

You shouldn’t even be disabling scripts and enabling scripts in the first place. thats bad practice, as I said you should use module scripts to handle those functions and what you want to do

So how would I do loops within function scripts for example while true do loops and while wait() do loops etc etc

local function foo()
    while true do
        wait()
    end
end

but what would I do to break it ?

Also what would I use to break all the other functions to stop them from interfering

Correct me if I’m wrong, but when requiring a module by id it can’t access its children. I believe it works as a independent piece of code outside the hierarchy.

Edit:
NVM. I’ll check that out really fast.

I have other modules published that can access there children.

1 Like

I’m still testing, it might be because scripts can’t run from nil, which is probably the parent of the module code’s container (if it has one).

Try adding print(script.Parent), if it’s nil then you’ll want to reparent the scripts to Workspace or ServerScriptService in your code when setting disabled to false.

I want the module published tho and not kept in game.
The module works if its in-game fine, But if i require it via id it don’t work.

Okay, I’m pretty sure this is the problem. Scripts basically only run when ancestors of ServerScriptService or Workspace (some exceptions like tools). Your module is in Workspace or ServerScriptService, but when you require by id its parented to game.Model, where scripts don’t run.
(if you’re curious, you can do something similar by parenting your module to ServerStorage, then notice how that causes the same problems as requiring by id)

All you need to do is at the start of your code move the loops folder to ServerScriptService, then reference it from a variable. You can also move the individual scripts to ServerScriptService or Workspace too.

So basically, you need to move your scripts to ServerScriptService or Workspace to have them run.

local function foo()
    while true do
        wait()
        if true then
            break
        end
    end
end

it’s literally just a single “break”