function StepUtils.bindToSignal(G,R)if typeof(G)~="\082\066\088\083\099\114\105\112\116\083\105\103\110\097\108"then error("\115\105\103\110\097\108 \109\117\115\116 \098\101 \111\102 \116\121\112\101 \082\066\088\083\099\114\105\112\116\083\105\103\110\097\108")end if type(R)~="\102\117\110\099\116\105\111\110"then error(("\117\112\100\097\116\101 \109\117\115\116 \098\101 \111\102 \116\121\112\101 \102\117\110\099\116\105\111\110\044 \103\111\116 \037\113"):format(type(R)))end local d=nil local function q()if d then d:Disconnect()d=nil end end local function E(...)if d and d.Connected then return end if not R(...)then return end if d and d.Connected then return end local E={...}d=G:Connect(function()if not R(unpack(E))then q()end end)end return E,q end
--[=[
	Binds an update event to a signal until the update function stops returning a truthy
	value.

	@param signal Signal | RBXScriptSignal
	@param update () -> boolean -- should return true while it needs to update
	@return (...) -> () -- Connect function
	@return () -> () -- Disconnect function
]=]
function StepUtils.bindToSignal(signal, update)
	if typeof(signal) ~= "RBXScriptSignal" then
		error("signal must be of type RBXScriptSignal")
	end
	if type(update) ~= "function" then
		error(("update must be of type function, got %q"):format(type(update)))
	end

	local conn = nil
	local function disconnect()
		if conn then
			conn:Disconnect()
			conn = nil
		end
	end

	local function connect(...)
		-- Ignore if we have an existing connection
		if conn and conn.Connected then
			return
		end

		-- Check to see if we even need to bind an update
		if not update(...) then
			return
		end

		-- Avoid reentrance, if update() triggers another connection, we'll already be connected.
		if conn and conn.Connected then
			return
		end

		-- Usually contains just the self arg!
		local args = { ... }

		-- Bind to render stepped
		conn = signal:Connect(function()
			if not update(unpack(args)) then
				disconnect()
			end
		end)
	end

	return connect, disconnect
end
