Disconnecting from an rbx signal

Im unsure if this is the right place but why not

how would i Disconnect from a rbx signal when you used function()

game.Workspace.Part.Changed:Connect(function()

end)

how would I disconnect from that

local a

function here

A:disconnect()

i believe thats how it goes

local a
game.Workspace.Part.Changed:Connect(function()

end)
a:Disconnect()

i could be wrong but if im correct thats it

Almost it, you have to set A to the connection though:

local a
a = game.Workspace.Part.Changed:Connect(function()

end)
if a ~= nil then a:Disconnect() end
4 Likes

A minor nitpick, you can actually just do

if a then a:Disconnect() end

to check if something is not nil.


Do note that whenever you are checking whether a boolean is nil, the behavior will be different.

local a = true

if a then
	warn("yes the boolean is true")
end

I know, I usually do that, but for this case making sure it’s not nil just feels better lol