I'm looking for a new method to disconnect a function, because the wiki says that the :disconnect() function is obsolete.

Here is the script I'm working on if anyone can help.

local plr = game.Players.LocalPlayer
local M = plr:GetMouse()

local fr = script.Parent
local T = fr:WaitForChild("TextLabel")

function TestFunction()
	print("Clicked")
end

M.Move:connect(function()
	fr.Position = UDim2.new(0, M.X, 0, M.Y)
	if M.Target ~= nil then
		if M.Target:IsA("Part") then
			if M.Target.Parent:FindFirstChild("Base") then
				fr.Visible = true
				T.Text = tostring(M.Target.Parent.Name)
				M.Button1Click:connect(TestFunction())
			else
				fr.Visible = false
				TestFunction:Disconnect() -- Error is here
			end
		end
	else
		fr.Visible = false
		TestFunction:Disconnect() -- Same error here
	end
end)

How could I fix this?

3 comments

1

disconnect() doesn't work anymore, but using Disconnect() works fine. If you're getting an error, it's probably because your function isn't connected to an event, so there's nothing to disconnect.

0

Ok thanks, I found another way too is using debounce XD