Does Disabled Script Auto DIsconnects Connections?

Hi :wave:, I’m been working on a :pizza: pizza Delivery :pizza: game and currently on the ‘Skill system’ thing.

  1. What I got currently so far
    image
    • So my idea is using LocalScript for each skill, store it in Player Backpack and only Enable what player Equipped and Disable when player UnEquip it.

    • Let take this simple script as an Example.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Sound_Remote")
local UIS = game:GetService("UserInputService")

local Connection = UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		Remote:FireServer("Shield")
	end
end)
  1. What do you want to achieve?

    • I want to optimize the memory usage as much as possible by disconnect all the Connection(s) when the script is Disabled

    • Got the answer for “when the script got disabled, does it auto disconnect the connections in it or its just pause the script and back to running when Enabled”

  2. What is the issue?

    • The problem is, I don’t know how to Disconnect the connections when the script is Disabled… ( . _ . )
  3. What solutions have you tried so far?

  • I been searching Forum for few days and haven’t find any problem similiar…
  • I’ve try to use connect a function that use to disconnect the connection using :GetPropertyChangedSignal("Disabled")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Sound_Remote")
local UIS = game:GetService("UserInputService")

local Connection = UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		Remote:FireServer("Shield")
	end
end)

-- disconnect when the script is not Enable
script:GetPropertyChangedSignal("Disabled"):Connect(function()
	if script.Disabled == true then
		print("Disconnected")
		Connection:Disconnect()
	end
end)
 - this is what the script look like
  • And… it not working, its doesn’t print anything.

So what I want to know is there any way to disconnect the connections when script disabled or any suggestion on optimize the my system. Thank you very much! :smiley:

Yes

I would probably disconnect any connections I have before disabling it, just to make sure. But I think you don’t have too, since the script doesn’t work, it won’t run, meaning there won’t be any connections.

If you wanna disable connections in a disabled script use MetaTables and store those connections in some module

I think you can simple test by printing when you pressed the keyboard, and disable script
I don’t know is it disconnect too, but you can using shared, _G, modules, to contain connection and disconnect it, if it doesn’t disconnect

"I'm not good at English, sorry for grammar"

They do disconnect when you disable your script. If you don’t believe me bind to an event and if its fired the script will get deleted. The script will never get deleted because its disabled and all connections are severed