Task.wait inside coroutines

Hello! I’m experiencing a problem where a coroutine yields / doesn’t complete occasionally, which has caused the bool value running to get stuck. Here’s a snippet:

	print(state.Parent.Name, state.Value, running.Value, Tick)
	if state.Value == false and running.Value == false then
		running.Value = true
		coroutine.resume(coroutine.create(function()
			for _,Engine in pairs(Engines) do
				Engine[string.sub(state.Parent.Name, 1, 1).."DoorClose"]:Play()
			end
			warn("A", Tick)
			task.wait(self.train.Utility.Doors.Config.ChimeCloseWait.Value)
			warn("B", Tick)
			Network:FireAllClients(self.train, false, Side)
			warn("C1", Tick)
			local CloseTime = DoorFolder.Config.Close.Time.Value
			warn(CloseTime, Tick)
			task.wait(CloseTime)
			warn("C", Tick)
			state.Parent.Value = DoorFolder.Config.Close.Value
			running.Value = false
			print(Tick, "[DoorHandler]", running.Parent.Parent.Name, running.Value)
			warn("D", Tick)
		end))

Prints and warns are present for debugging purposes and here’s a resulting screenshot:

Please note that the “Static Tick” is debugged as the coroutine is called many times and sometimes it’s a hit or miss. The code snippet is lines 52-73.

Thank you!

For clarity: task.wait(CloseTime) is where it hangs.

You could print out the return values of coroutine.resume and see if you are getting an error when it completes.

1 Like