Is it bad practice not to disconnect an event when not in use?

My plane handler is almost complete. I was having problems with disconnecting Stepped in my local script since it handled most of the plane stuff and disconnecting it mostly breaks the whole script.

I’m better of returning, any other solutions?

local connection	
connection = RunService.Stepped:Connect(function()
			-- Fires on physics simulation,	useful when handling objects
			unanchored and their properties associated with it.
			If statements used to prevent values changing unnecessarily, helps in keeping
			efficient memory, though only improving 0.000000000000001% memory.
            / Functions	
		    default() -- Calls the function to reset all the values associated with the plane 
		if CURRENT_PLANE_SPEED <= STALL_PLANE_SPEED then-- Plane speed <= 0, secures the if statement
		if not planeEngineOn then
		if not seatValue.Value then -- No Player found in seat, turn off the engine
			planeEngineOn = not planeEngineOn
	   if not engineSound.Playing then
			engineSound.Playing = not engineSound.Playing
		engineSound.PlaybackSpeed = CURRENT_PLANE_SPEED / (CURRENT_PLANE_SPEED + 1)

Disconnecting functions that aren’t in use will save game resources, but It’s not necessary to do It always, if you say that disconnecting your function breaks It, then don’t disconnect it.


If it needs to run on every stepped then its fine, but if you doesn’t then yes you should disconnect it.

1 Like

It’s for handling the plane. What do you think?

Not disconnecting an event will use up game resources. :exploding_head:

If it is unnecessary to anything, it doesn’t need to be run. :+1:

Exploiters may have the ability to use one of those if they detect there is one, so I suggest you deplete unnecessary events. :man_shrugging:

If disconnecting the event, when not in use, disables the use of the active scripts, I suggest you don’t disconnect it.

1 Like

Is the plane controlled by the user? If it is then only run it when the user is interacting the plane.