Return not working in a coroutine

So I was coding a coroutine, and it doesn’t seem to work right. I am calling return at the end.
What is happening is when I call the coroutine, it is not yielding for results.

Here is some code:

The one calling it

local _, didfinish = coroutine.resume(checkcoroutine, racesize)

The actual coroutine:

local function setupcheckco()
		if checkcoroutine then
			coroutine.close(checkcoroutine)
			local spot = table.find(zoneline[racesize], id)
			if spot then
				table.remove(zoneline[racesize], id)
			end
		end
		print("got here")
		checkcoroutine = coroutine.create(function (size: string): boolean
			print("started")
			local options = zonefolder:FindFirstChild(size):GetChildren()
			if #options > 0 and #zoneline[size] == 0 then

			else
				print("adding")
				table.insert(zoneline[size], id)
				local done = Instance.new("BoolValue")
				local eventcon
				eventcon = FrontLineEvent.Event:Connect(function (frontid)
					if frontid == id then
						eventcon:Disconnect()
						done.Value = true
					end
				end)
				checkcon = eventcon
				print("waiting")
				done.Changed:Wait()
			end
			print("finishing")
			unoccupied[size] -= 1
			return true
		end)
	end

I think coroutines are threads and not functions and thats why they might not be returning any values. I’m not actually sure, but thats just what I think is the reason why its not working as you’d expect.

1 Like

There is a code example using this conecept.

From the link:

Also, the issue is when I call the coroutine it is simply just calling at and then moving on without waiting for results

With the scenario, it feels like I’m just doing task.spawn

Turns out that this is expected behavior. The engine only waits one cycle for a answer. Of course I am waiting millions of cycles.

I found a different way to do this. Thanks @Katanasoldier for trying to help!

1 Like