Any way to break this loop from RunService.Heartbeat?

Yoo you’re remaking GMod physics? Ayyyy

Check the other video too

Also you can play the game if you want

I’m doing something forbidden right now, but we’re getting there.

	local coro = coroutine.create(function()
		while IsGradient == true do
			create:Play()				
			create.Completed:Wait() --wait for tween to stop
			createRev:Play()

			create1:Play()					
			create1.Completed:Wait() --wait for tween to stop	
			create1Rev:Play()
			if IsGradient == false then
				coroutine.yield()
			end
		end	
	end)		
	
	if IsGradient == true then
		coroutine.resume(coro)
	else 
		IsGradient = false
		gradchange.Color = (GradientPresets["Default"])			
		gradchange2.Color = (GradientPresets["Default"])
	end

Any idea on entering the coroutine, leaving, and then going back into it?

I only really know how to do one time coroutines sadly since I mostly used them for effects in gun engines and a lobby system

also the game L-Mod has thousands of lines of code and took way too long to make for the amount of attention it got.

I solved the issue with the help of those that commented.

My main hold up was buffering the loops so there was time to cancel if the flags were changed.