I attempted to do this using Changed to detect when the Connected property in the connection is changed, but received the error below:
Is there any possible way I can detect the INSTANT a connection is disconnected, without using a repeating loop? If not, is there a way I can wait until I make the connection = nil?
I do not see the necessity for context. I am simply asking if it is possible to do. If I provide context, people may try to provide me an alternative method, such as saying I can do:
repeat task.wait() until not connection.Connected
This is not my goal at all, and I want to do exactly as I described rather than a workaround.
There is no way to detect when a connection was disconnected without repeated checks. Generally what you’d want to do is perform whatever action that needs to happen precisely where you actually perform the disconnection.
local Connection
Connection = function(something)
if condition == true then
Connection:Disconnect()
Connection = nil --Set it to nil to easily check if connection exists
--Perform necesarry actions here
end
end
having a loop check the status of a connection is also possible but seems unnecessary. If you want to check if a connection is active whether by loop or single action, an if statement will easily be good enough
if Connection then
--do stuff
else
--No connection
end
RBXScriptConnection doesn’t provide any events for its disconnection. Polling the .Connected value, using a custom implementation of Signal that provides this feature, or manually firing another signal/calling a function after :Disconnect() is called are the only ways to wait until a signal connection is disconnected.
RBXScriptSignals and RBXScriptConnections are not Instances so they don’t have built-in change signals.
You state that you want to wait until the variable holding the connection is nil. Simple variables do not signal when they’re changed. Polling is also the only way to detect a change. If this connection is stored in some sort of proxy table implementation, then the __newindex metamethod of that implementation can fire a signal when the connection entry is set to nil. I’d suggest you reflect and pivot your concern away from signal connection disconnections. There’s probably a more intuitive way to accomplish your goal.