Attempt to index function with "Disconnect()", except it is a function...?

local function finalSlashHitDetectionFunction(hit)
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= "clone" then
				print("HHHHHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIIITTTTTTTTTTTTTT")
			end
end
		
		finalSlashAnim:GetMarkerReachedSignal("superSlashEffectTrigger"):Connect(function()
			
			--connect damage function
			plr.Character.HumanoidRootPart.Touched:Connect(finalSlashHitDetectionFunction)
		


		finalSlashAnim:GetMarkerReachedSignal("superSlashStop"):Connect(function()

			--disconnect damage function
			finalSlashHitDetectionFunction:Disconnect()

This is all inside of a bigger function that is a remote event.
I’ve also deleted a lot of additional stuff to keep it simple (those are all for visuals, I believe they have no relevance to the problem).

The error is on the final line. The error of course being stated in the title, "Attempt to index function with “Disconnect()”.
I honestly don’t know how to even explain what I think could be the problem or anything at all honestly, I’m just at a loss for words. I see zero reason why this shouldn’t work. Yes, I am attempting to index a function. Because it is a function.
???

1 Like

You can’t disconnect a function. You can only call it on RBXSCRIPTSIGNALS. Of which this isn’t. Instead you have to disconnect the .Touched event.

local con 
local function finalSlashHitDetectionFunction(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= "clone" then
		print("HHHHHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIIITTTTTTTTTTTTTT")
	end
end

finalSlashAnim:GetMarkerReachedSignal("superSlashEffectTrigger"):Connect(function()

	--connect damage function
	con = plr.Character.HumanoidRootPart.Touched:Connect(finalSlashHitDetectionFunction)



	finalSlashAnim:GetMarkerReachedSignal("superSlashStop"):Connect(function()

		--disconnect damage function
		con:Disconnect()

oooh
okay

so could i say “plr.Character.HumanoidRootPart.Touched:Disconnect()” or “plr.Character.HumanoidRootPart.Touched:Disconnect(finalSlashHitDetectionFunction)”?

or does it have to be like the connection itself im disabling, meaning i have to make a variable for the connection part like you did?

it has to be a connection itself to disable.

yep

here’s your problem which @TheH0meLands already explained, in simpler terms.

say if you had a function you wanted to disconnect from an event:

Instead of saying:

function touched(part)
   if part.Parent.Humanoid then
    print("I was touched by a player!")
    touched:Disconnect() // this wont work!
  end
end

part.Touched:Connect(touched(hit))

Say:

local connection

function touched(part)
   if part.Parent.Humanoid then
    print("I was touched by a player!")
    connection:Disconnect() // this works!
  end
end

connection = part.Touched:Connect(touched(hit))

The :Disconnect() function disconnects an function from a event. not a function from a function. In other words, an event can have multiple functions tied to it, if you say event:Disconnect(), how will the script know which function to disconnect? :Connect() and :Disconnect() are opposites. Remember that.