Do I have to disconnect touch event even when part is destroyed?

local object = pathobject -- object as in random part in workspace or whatever
if object then 
    object.Touched:Connect()
     -- random logic
     object:Destroy()
    end)
end

Or

local obj = "objectunamehere"
if obj then 
local E -- I dont know what you call this but maybe 'event handler'??
E = object.Touched:Connect(function()
object:Destroy() E:Disconnect()
end)
end

dont they do the same? because the first code shows part destroyed meaning that the function is no longer active but same does the second one? which is best for performance? I just saw this from a free model rocket kit and thought I’d like to ask whats the main difference Thanks

5 Likes

When a part gets destroyed, all event connections to that part are also disconnected automatically so you don’t have to worry about that.

20 Likes

It doesnt work for me, Touched event fires even after my part is destroyed

1 Like