Quick Question on disabling connections

If I make lets say an OnClientEvent:Connect(function() then if I make a while true do loop inside that connection does Disabling the connection effectivley break the while true do loop
what I mean

	local Connection = Remote.OnClientEvent:Connect(function()
		while true do
			print("Will this loop break")
			task.wait()
		end
	end)
	task.wait(4)
	Connection:Disable()

if not how can I stop this loop when I disable the connection
Thanks!

  1. I think you mean :Disconnect()
  2. No it wouldn’t. Disconnecting from an event only stops the script from listening to the event.

To stop the loop in there as well you would do

	local Connection = Remote.OnClientEvent:Connect(function()
		while Connection.Connected do
			print("Will this loop break")
			task.wait()
		end
	end)
	task.wait(4)
	Connection:Disconnect()

To reset it to listen again, you would simply set byebye back to true on the client, and then have the server fire the event again.

A better approach would be using the RBXScriptConnection's Connected property.

local Connection do
    Connection = Event:Connect(function()
        while Connection.Connected do
        end
    end)
end
1 Like

You’re right. I completely forgot that property existed. Thank you for reminding me!

If I was using Bindables how would I do this like a wanted to do a repeat until the bindable is fired?