How to disconnect from RunService heartbeat event function

Hi. How can i disconnect Run Service Heartbeat function like this:

local cnt = 1
		
RS.Heartbeat:Connect(function()
	if cnt >= x then
		--disconnect from that function
	else
		...
	end	
	    cnt += 1
end)
local cnt = 1
local connection	
connection = RS.Heartbeat:Connect(function()
	if cnt >= x then
		connection:Disconnect()
	else
		...
	end	
	    cnt += 1
end)
1 Like

Thanks for that. Its really works

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