Waiting inside spawned thread calling "attempt to resume dead coroutine"

while true do
			task.wait(3)
			
			self.target = self:findNearestTarget()

			local path = PathfindingService:CreatePath()

			local success, response = pcall(function()
				path:ComputeAsync(self.creatureModel.HumanoidRootPart.Position, self.target.HumanoidRootPart.Position)

				local waypoints = path:GetWaypoints()

				if previousThread then
					task.cancel(previousThread)
				end

				previousThread = task.spawn(function()
					for _,waypoint in waypoints do
						self.creatureModel.Humanoid:MoveTo(waypoint.Position)
						self.creatureModel.Humanoid.MoveToFinished:Wait()
					end
				end)
			end)

			if not success then
				warn(response)
			end
		end

I am attempting to have a thread that moves to the waypoints however when it starts to wait for MoveToFinished roblox throws the “attempt to resume dead coroutine” error internally with zero stack trace information. Is there an undocumented roblox feature that addresses this?

That’s because you’re trying to resume a coroutine that has recently died.

To fix this, you have to check for coroutine’s status to make sure they’re not dead, so that they can be resumed.

im aware of what the error means… as I said above. the error originates from MoveToFinished yielding.

This seems to be a common issue: closing a task with Event:Wait() wrapped inside errors out. The link will direct you to a post, which provides a reason for the erroring; and, according to the same post, “This is an issue on Roblox’s end.”

1 Like

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