How to disconnect a touch function from within itself

How do I disconnect a touch function from within itself?

--example
function InputNameHere()
   local part = Instance.new("Part")
local touchFunc = part.Touched:Connect(function()
       touchFunc:Disconnect() -- raises a blue underline error, that this is not a valid global function.
end)
end

Based on my experience, I believe you have to declare the connection separate

local touchFunc
touchFunc = part.Touched:Connect(function()
   touchFunc:Disconnect()
end)
3 Likes

like, as in you delcare it outside of the function?
wait i see now

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.