Disable a Require() Module Script

Hi!

I am building a script to help me control all of my games via an external server. All of that is going smoothly, but I have run into a single problem.

Say I required a script somewhere in the code:

local module = require(...)

Later in the code, if I want this script to stop executing, how can I disable it?

module:Disable() -- How would I do this?

Keep in mind that I am requiring the script through an AssetID, not a module script instance in the game.

Thank you in advance, Bloxlin

Not enough information to provide a clear answer.

Ok how about this.

Say in a modulescript, I have the following code:

local module = {}

-- Prints Hello World every second
while wait(1) do
  print('Hello world')
end

return module

If you were to require this module via another script,

local module = require(...)

it would print “Hello world” every second.

How could I “Disable” this script so that it stops printing “Hello world”

Could you wrap it in a task and then cancel that task

1 Like

Wouldn’t recommend throwing a while loop in a module script, it just makes the whole module script being used for that task. There must be a better way to handle whatever code you’re doing.

The reason I am not actually taking advantage of the module is because I need to require it by the asset ID to execute whatever I need to happen.

That will add some complications, but I do believe that will work! Can’t believe I didn’t think of that :smiley:

1 Like

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