''Cannot close normal coroutine''

Hello, I need help closing my coroutine, because it currently errors…

		local function decreaseLifeTime()
			while true do
				task.wait(1)
				
				if messageLabel:GetAttribute("LifeTime") > 0 then
					messageLabel:SetAttribute("LifeTime", messageLabel:GetAttribute("LifeTime") - 1)	
				else
					break
				end		
			end
		end
		
		local lifeTimeCoroutine = coroutine.create(decreaseLifeTime)
		coroutine.resume(lifeTimeCoroutine)
		
		local attributeConnection
		
		attributeConnection = messageLabel:GetAttributeChangedSignal("LifeTime"):Connect(function()
			if messageLabel:GetAttribute("LifeTime") > 0 then return end
			attributeConnection:Disconnect()
			
			coroutine.close(lifeTimeCoroutine)
			
			tweenService:Create(messageLabel, tweenInfo, {TextTransparency = 1}):Play()
			tweenService:Create(uiStroke, tweenInfo, {Transparency = 1}):Play()

			debris:AddItem(messageLabel, tweenInfo.Time)
		end)
3 Likes

I’ve seemed to fix this by closing the coroutine inside of the coroutine:

		local lifeTimeCoroutine
		
		local function decreaseLifeTime()
			while messageLabel:GetAttribute("LifeTime") > 0 do
				task.wait(1)
				messageLabel:SetAttribute("LifeTime", messageLabel:GetAttribute("LifeTime") - 1)
			end
			
			coroutine.yield(lifeTimeCoroutine)
			coroutine.close(lifeTimeCoroutine)
			
			print(coroutine.status(lifeTimeCoroutine))
		end
		
		lifeTimeCoroutine = coroutine.create(decreaseLifeTime)
		coroutine.resume(lifeTimeCoroutine)

Correct me if I’m wrong, though.

3 Likes

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