The Connect method returns a connection. So to disconnect you need to capture the connection into a variable then you can use the Disconnect method on the connection
local connection = script.Parent.ClickDetector.MouseClick:Connect(function()
--there's no function name so how can I disabled it?
end)
connection:Disconnect()
Yes it will, because if you don’t you may hog up untracked memories which will decrease server performance. Also, it’s called disconnect an event, not disconnect a function.
function Click()
print("Clicked!")
Click:Disconnected()
end
script.Parent.ClickDetector.MouseClick:Connect(Click())
Just to let you know in your original function “Disconnected()” isn’t a valid method and you don’t need to call the callback you’re connecting to the event you just need to reference the callback you’re connecting by name.
Potentially, it certainly keeps memory clean, which is always a good thing and it is a good practice to disconnect events if they are no longer needed. If you have many events then it is possible the difference in performance would be noticed, but it there are only a few connected events running in the game I doubt anyone would notice the difference. It also depends on what is happening when the event is triggered. If it is a long running process then the difference is likely to be more noticable but again if it does little then it is debatable whether the difference would be noticed. You will only know through testing.