Coroutine not resuming when i call it

hello all. I have this script setup and everything is functioning to a dime except for the coroutine i made. basically what I have here is a game that keeps track of your progress and locations discovered, so for example when you step on a ‘finishPart’ it fires a remote event etc. etc. which is all functioning great, except I want it so that when you change screens in the menu, it updates the text on the label to whether it should say complete or not. It doesn’t seme to be functioning, and I have a feeling it’s because I completely incorrectly wrote my coroutines but some of the API is confusing me on them.

for i,v in pairs(mapData) do
	
	local changeCompleteStatus = coroutine.create(function()
		if v.completed == true then
			sampleFrame.isCompleted.Text = "level "..v.level" has been completed"
			print("level is complete!")
		else
			sampleFrame.isCompleted.Text = "level "..v.level" has not been completed"
			print("level is not complete")
		end
		end)
	
	print(v.level)
	local mapFrame = script.Parent.sampleText:Clone()
	mapFrame.Visible = not mapFrame.Visible
	mapFrame.Parent = script.Parent
	mapFrame.MouseButton1Click:Connect(function()
		sampleFrame.Visible = true
		progressMenu.ScrollingFrame.Visible = false
		coroutine.resume(changeCompleteStatus)
		
		sampleFrame.xButton.MouseButton1Click:Connect(function()
			sampleFrame.Visible = false
			progressMenu.ScrollingFrame.Visible = true
			coroutine.resume(changeCompleteStatus)
			end)
		end)
end

The coroutine finishes executing the first time you call resume so there’s nothing to be resumed the second time you call it. Resume is meant to start a created coroutine or resume a yielded one but it’s not the same as calling a function again, so rather than it not working it’s that you aren’t using them right.

It doesn’t really look like you need coroutines here. Example replacement for coroutines:

-- Don't know if "v.level" is a number or string; %d if it's a number
local levelStatus = if v.completed == true then "has" else "has not"
isCompleted.Text = string.format("level %s %s been completed", v.level, levelStatus)
1 Like

ok thank you very much! I still have a lot to learn on coroutines so I’ll keep them in mind for next time when I might use them cause I haven’t yet found a use