How would I make a connection disconnect itself?

So I’m looking to optimize my code a little bit further, and I want to be able to have a script connection disconnect itself. I don’t think it’s possible to disconnect it inside the function? I’ve been researching for about an hour or two and I can’t find anything because it’s a very niche problem.

local signal3 = track.Ended:Connect(function()
	print("Animation Track Ended")
	--Do code here
	signal3:Disconnect()
end)

Does anyone know how to do something like this?

1 Like
local signal3
signal3 = track.Ended:Connect(function()
	print("Animation Track Ended")
	--Do code here
	signal3:Disconnect()
end)
2 Likes

Oh wow is it really that simple?

3 Likes

By the way, you can just delete the script itself if you don’t use it anymore.

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