I’ve been told be a friend that RBXScriptConnection and RBXScriptSignal are useful resources in many scripting instances, such as tools, functions, and more. I read the documentation on these, but the documentation made no sense to me. (I don’t really know what it means to ‘disconnect a listener’, etc.) I would just like some clarification on everything related to these, so I can learn more about scripting.
RBXScriptSignal is basically an event Instance that allows you to listen to events that it fires using certain functions (we call these functions listeners).
RBXScriptConnection is an Instance that gets created from RBXScriptSignal when you want to listen to the events that RBXScriptSignal fires. It basically allows you to connect and disconnect from RBXScriptSignal.
A common example would be a RemoteEvent Instance that you can connect to from the Server to listen to the client events.
-- RemoteEvent.OnServerEvent is an RBXScriptSignal Instance.
RemoteEvent.OnServerEvent:Connect(function(...) -- Connecting a listener function to the RBXScriptSignal Instance (OnServerEvent)
...
end)
-- And the function :Connect() returns an RBXScriptConnection instance that you can reference like below:
local Connection = RemoteEvent.OnServerEvent:Connect(...)
-- This is now a reference to the now created RBXScriptConnection Instance!
Connection:Disconnect() -- Disconnects from the OnServerEvent RBXScriptSignal Instance, so you can no longer listen to any events coming from the client.