Is it bad if I will disable and re-enable a script with 1000+ codes everytime?

Hi, I got this question because my game has a regeneration script that regenerates everything. All scripts that are inside the ServerScriptService are disabled during regeneration and enabled again when regeneration ends. This is to reset all scripts.

So, is it bad if I disable and re-enable a script with 1000+ lines for regeneration? Moreover, if it has connections like MouseClick, Touched, etc.

If yes, is it good if inside every script will be a bindable event connection to regenerate variables, etc.?

3 Likes

I don’t really see any glaring problems by doing this, besides maybe a little bit of lag due to the scripts all starting up again. If everything works and isn’t too laggy then I guess there isn’t really a reason to change anything.

2 Likes

It’s a bad idea disable/enable script constantly.
Not for any perfomance reason, but more rather that it’s just bad code design.

So, will it be better if I use a bindable event connection inside a script to regenerate its variables, etc.?

What are you even trying to regenerate?

try including pictures along with what you are regenerating

Basically, if a script is connected to the model that is being used by players during a round, it will be regenerated, and all variables will also be regenerated inside the script.

For example, there is a box that players will use. You can open it and close it. So it is necessary that this box be closed after regeneration. Example code:

local Opened = false

MouseClick:Connect(function()
    Opened = not Opened
    --set the box position to opened/closed
end)

local RegenEvent = BindableEvent
RegenEvent.Event:Connect(function()
   Opened = false
   --set the box position to closed
end)
1 Like

Well then, yes. You should use BindableEvents.