Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I delete an Event?

Asked by 5 years ago

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?

0
check if the button's text is the one you want Leamir 3138 — 5y
0
@Leamir How will that help with removing the event and not creating multiple instances that run at the same time? doncellanerdy 21 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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()
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. doncellanerdy 21 — 5y
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 fanofpixels 718 — 5y
0
Thanks, connected might be useful in the future. doncellanerdy 21 — 5y
Ad

Answer this question