Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I delete an Event?

I have a GUI with a button when an object is selected I what one of two things to happen. Insert the object into a list or in the object is already in the list then to be able to edit it.

I could just swap out buttons but I thought I could use the same button. Just change text and events. I have yet to create the edit function but I have the insert function working but I kept getting multiple inserts so I added a debounce but still had the same problem.

So the problem is that although I use disconnect to turn the event off when I turn it back on it just creates a new instance that runs in parallel. I tried to destroy, remove and nil the variable for the connection but I get errors or the same problem.

So is swapping out the buttons my only solution or am I missing something?

2 comments

0

check if the button's text is the one you want

0

@Leamir How will that help with removing the event and not creating multiple instances that run at the same time?

1 answer

when you connect an event, it actually returns something called an "RBXScriptConnection", and if you no longer want the event attached to the instance, make sure its saved to a variable so you can call "Disconnect".

local MyEvent = script.Parent.Something.Thingy.Part.Touched:Connect(function()
	print("Hello!")
end

-- to delete an event:
MyEvent:Disconnect()

3 comments

0

I use this, and it does stop the event from executing but if I recreate the event I get two event that run simultaneosly. Don't know why. Is there a why to reactivate the event since it seems to not really delete it but only deactivate it.

0

there does not appear to be a method for reactivation, but you could try setting MyEvent.Connected, though i doubt it will work :\ https://developer.roblox.com/en-us/api-reference/datatype/RBXScriptConnection

0

Thanks, connected might be useful in the future.

This discussion is preserved as it was. New answers, comments, and votes are closed.