Destroy||doc136356

September 20, 2022

Format

BindHandle:Destroy()

Describe

Unbind the event function by destroying the handle of the event binding function.

Code example

Click the event in the binding window, and click 5 times to cancel the binding.

-- Create an Image control
local window = UI:CreateGUIWidget(Enum.WidgetType.Image)
window.Parent = UI.Root

local clickTimes = 5

-- Bind the window click event
local event = window:GetEvent("OnClick")

-- The handle returned when saving the bound function
local handle = event:Bind(function()

     print("click window!", window.name)
    
     -- Destroy the handle after 5 clicks
     clickTimes = clickTimes - 1
     if clickTimes == 0 then
         handle:Destroy()
     end
end)