Where all events are stored when we overwrite a variable

part = workspace.Part
button = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").TextButton

local touched

button.MouseButton1Click:Connect(function()
	
	touched = part.Changed:Connect(function()
		
	print("me_change___________")
	end)
	
end)

Where all events are stored when we overwrite a variable. Let’s say I press a button. My variable touched = event #1 . I press the button again. My variable touched = event #2. Yes, it was overwritten, but event#1 will continue to work. Can I call event#1 disconnect? And if I press the button 100 times and I have the variable touched = event#100, will I be able to interact with other event#1 somehow…event#99? Where do they go? Where are they stored? How do I see it if the variable is overwritten?

You can still call event:Disconnect() as long as its disconnected before you overwrite the variable again.

But i dont know what happens to the event when its set to nil, so the best i could do is give you this advice which is more efficient:

Another easier solution you can use for connecting events in these scenarios is :Once instead of :Connect which work like :Connect(), except that when the event gets ran once, it automatically gets disconnected.

1 Like

Yes, I know, I’m just wondering where exactly all the events are stored. How this work in Roblox?

Those are stuff you should figure out by your own, but my guess is that events are stored the same way as variables.

just variables
a = 4
a=7

okay, the variable was overwritten, the number 4 is gone forever

a = event#1

a=event#2

event#1, still working.

So I wonder where event#1 is located.))

Oh i see, the event will just keep running until the disconnect function gets called

You can use tables instead to store multiple events without overwriting them

1 Like

Yes, this can be done, it’s understandable, but there is little if any function that can show something like this without resorting to arrays.

Again you can use the :Once() function that will only run the event once.