Script still running/causing errors once its been deleted

I’m developing a world loading system, and it works fine aside from the fact that loops like “while task.wait() do” that require certain parts cause errors when the world is unloaded since the parts are deleted upon the world unloading.

I usually get these errors most of the time:

  • X is not a valid member of Y
  • Attempt to index nil with X

Something else to note; the worlds are being loaded in from ReplicatedStorage, meaning having regular scripts wont work for some reason. To circumvent this, I have an “OnStart” folder in the scripts folder of each world, in this folder I have ModuleScripts each with a “:StartScript()” function. I feel like this is partly the reason as to why this is happening.

Is there a way to stop these errors from happening or silencing/stopping execution of these scripts altogether when deleted?

Scripts in ReplicatedStorage tend to work fine for me, but maybe try disabling them when they aren’t in use? I don’t use modules too much so…

1 Like