Custom execution requirements for scripts

Hello,

I’m trying to make a module that populates tagged objects with specified objects. I’m trying to make it so that BaseScripts only run once all ancestors have finished being processed for population, however, scripts seem to run immediately once placed into the DataModel and the server doesn’t even detect scripts created before the game was run.

My previous system used module scripts tagged as server and client scripts but there are a couple of disadvantages, notably:

  1. Scripts and local scripts stop executing once removed but module scripts being required and called won’t stop once the module script object is removed.

  2. Clients can see server code because the source code of module scripts is replicated whereas server scripts don’t. This also makes my game use more network resources to replicate things clients shouldn’t even be able to see.

  3. They seem to lag when I call WaitForChild()?

  4. All events created by the script are unbound.

How would I implement my desired behavior?

Thanks,
Rad

As soon as you remove all references to your script/module and destroy them, they should have stopped working after all the code has been executed.

Clients can not see objects in ServerStorage and ServerScriptService

Please provide some code for us to analyze

Never mind about all I said, I forgot that LocalScripts can’t be ran in the workspace so using them wouldn’t be a good choice.

Also, in order to get my desired behavior with module scripts, you can wrap the run method in a coroutine, run it with coroutine.create() and when the module script is deleted, running coroutine.yield will stop coroutine execution and events bound will not be called.

EDIT: Turns out this isn’t the case for some events like RunService.RenderStepped don’t get unbound. A solution to this problem was found in this thread.

1 Like

try using a BindableFunction or BindableEvent?