How to disconnect function

How do i disconnect the function, NOT the MouseButton1Click Event.
I want if the Player click the Button that the function a() should not start twice, so i want to disconnect the function a(), how do i do that?

local connection

local function a()
	connection:Disconnect()

	
	
	end
	
connection = script.Parent.MouseButton1Click:Connect(a)

I’m not too sure what you mean. In this case, you can only disconnect the MouseButton1Click, which is what you’re doing.

local connection

local function a()
	connection:Disconnect()

	
	return
end
	
connection = script.Parent.MouseButton1Click:Connect(a)
1 Like

The Player cant click the Button again, i dont want to disconnect the MouseButton1Click, i want to Disconnect just the function

I’m almost certain that would disconnect the connection before you can click.
I don’t think it yields

local connection

local function a()
	connection:Disconnect()
end

connection = script.Parent.MouseButton1Click:Connect(a)

The player wont be able to click the button again if the above code runs, since the connection gets disconnected.

In this case, you wouldn’t need to disconnect anything?

Just do this

local function a()
	-- code here
end

script.Parent.MouseButton1Click:Connect(a)

You can just use :Once(), and create another connection in the function that fires only once

local newconnection

local function a()
   newconnection = script.Parent.Event:Connect(function()
      --code
   end)
end

script.Parent.MouseButton1Click:Once(a)