Disconnecting & Connecting

I have a question, how can you disconnect and connect a function back again? I’m currently trying but it appears there is an error. I want it so if a player touches a part it fires a remote event, disconnect it then, lastly connect it back in 4 seconds so everything works again.

local event
event = script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		script.Parent.RemoteEvent:FireAllClients(hit.Parent.Name)
		event:Disconnect()
	end
    wait(4)
	event = script.Parent.Touched:Connect(hit) 
end)

I believe you are looking for a debounce to disable the event for a certain amount of time after running once.

Otherwise it’s possible and another way to do it I believe but you need to store the function used within the event in another variable and use it but debounces should do the same job.

1 Like

Thank you, the debounce was a better solution.