#Dont know how to end functions with event listeners

13 messages · Page 1 of 1 (latest)

wispy oar
#

title, i want to know how i can avoid memory leaks with functions that have event listeners in them? im looking everywhere but nothing has a solid resource lmao

verbal flax
#

im not sure what this title means

#

can you be more clear

unkempt yew
#

It's a simple as that

verbal flax
#

if you want it disconnect as soon as its run once

#

you can use :Once() instead of :Connect()

#

if you want to know how to disconnect connections generally

#

define the connection in a variable and call the :Disconnect() event on the variable that defines the connection

#

for example

#
part = workspace.Part

connection = part.Touched:Connect(function()
  -- blah blah blah
end)

task.wait(3) -- lets say you wanted it to disconnect after 3 seconds

connection:Disconnect()
unkempt yew
verbal flax
#

yeah I wrote it in like 5s