Is there a way to "unrequire" client module scripts?

I’ve made a TERRIBLE mistake where a Gui script contains a LocalScript in which holds a bunch of help module scripts, I’m almost done with my game, but haven’t tested dying up until now. I’ve noticed that after death, the module scripts fire twice, and then fires 3x after the third death and so on.

The LocalScript is under a ScreenGui that resets upon death. Simply making it not reset upon death breaks everything. I preferably do not want to restart my scripts all over again as I’ve made thousands of lines of work already.
image

Below is an example of a module script holding 2 errors after the third death:
image
Presumably from the 2 previous character lives where they still function and respond to such as User Inputs.

This of course is not ideal, but I am too deep into this game to change it all, I understand now what I did is a mistake, but is there a way to almost cancel or unrequire module scripts?

There is no way to “unrequire” a module script. I recommend not requiring the module script at all or only requiring it once.

3 Likes

Ah heck, looks like I gotta restart everything :sad:oh well, its a learning process.

2 Likes

Why do you need to restart it all? Your error is caused because an object called “Sound” is not part of the ModuleScript, you should just fix this.

Sound is most definitely a part of the modules script, I’ve noticed that this behaviour occurs when scripts are destroyed but they are still functioning and you attempt to call a child of it.
Because a lot of my variables are defined at the start of the script, for example Humanoid etc.

You should switch it to :FindFirstChild() and create an if statement checking if “Sound” is found.

I’ve tried that, it’s because it’s under a local script that gets destroyed as the GUI resets upon spawning. Meaning all the module scripts under it are destroyed, I’ve tested it by having a random number be printed when this function is used, and the previous number along with the most recent number is being outputted indicating that the module script is still functioning despite being destroyed.

Does the Main ScreenGui have ResetOnSpawn enabled? If so, you can most likely fix your problem by unchecking it.

It does, but there are problems that come with it. Is that the only option do you think?

Sounds like you played yourself. Disabling ResetOnSpawn should be one of the first things you do when you spin up a place file.

If you’re stuck with this, relocate the modules to a static container like ReplicatedStorage so they don’t reload with the rest of the UI.

2 Likes

I see my mistake now, I’ll simply just have to rework my script so that it works with it being kept on despite respawning.

1 Like