Is there a way to reconnect a function after disconnecting it?

This is unfortunately wrong. You can still use a function after it is disconnected.

local function myFunction()
    -- code
end

local myConnection = Event:Connect(myFunction)
wait(60)
myConnection:Disconnect()
myFunction()
-- it's possible to reconnect too as long as you have your logic correctly
myConnection = Event:Connect(someOtherFunction)

In your case you will want to review your logic.

First, this is called a closure. They are used when you want to segregate variables or functions which refer to the same function but with different values.

They are quite handy however using them on a large scale for no reason is a waste of memory as each closure with it’s variables will use a lot of memory.

It’s best to keep this all event based. I recommend using this boilerplate I created a while ago. I use it for tools it’s quite nice as there is only 1 event.

local Tool: Tool = script.Parent
local Player = Players.LocalPlayer

-- Variable
local LMB_Connection: RBXScriptConnection = nil
local RMB_Connection: RBXScriptConnection = nil

-- Events
Tool.Equipped:Connect(function(mouse: Mouse)-- Connect events after equip
	LMB_Connection = mouse.Button1Down:Connect(function()
		local Origin: CFrame = mouse.Origin
		
		mouse.Button1Up:Wait()
		
	end)
	RMB_Connection = mouse.Button2Down:Connect(function()
		
		mouse.Button2Up:Wait()
		
	end)
	Tool.Unequipped:Wait() -- Disconnect events after unequip
	LMB_Connection:Disconnect()
	RMB_Connection:Disconnect()
end)

If you would like your functions implemented as variables then this will too work.

local Tool: Tool = script.Parent
local Player = Players.LocalPlayer

-- Variable
local LMB_Connection: RBXScriptConnection = nil
local RMB_Connection: RBXScriptConnection = nil

-- Functions
local function LMB_Down()
	
end

local function RMB_Down()
	
end

-- Events
Tool.Equipped:Connect(function(mouse: Mouse)-- Connect events after equip
	LMB_Connection = mouse.Button1Down:Connect(LMB_Down)
	RMB_Connection = mouse.Button2Down:Connect(RMB_Down)
	Tool.Unequipped:Wait() -- Disconnect events after unequip
	LMB_Connection:Disconnect()
	RMB_Connection:Disconnect()
end)

I highly recommend the first way as you keep your arguments.

6 Likes