Coroutine loop Stop after Event

I want the coroutine loop to stop after a event is fired

local myLoop = coroutine.wrap(function()
local path:ComputeAsync(LHumanoidRootPart.Position,playerPosition)
		
		if path.Status == Enum.PathStatus.Success then
			for k, waypoint in pairs(path:GetWaypoints()) do	
				LHumanoid:MoveTo(waypoint.Position)
				LHumanoid.MoveToFinished:Wait()
			end
		end
end)

myLoop()
game.ReplicatedStorage.RemoveEventFolder.SoldierEvents.OnServerEvent:Connect(function(player,troops,pos:CFrame)
    myLoop.stop() -- where the loop would stop
end
coroutine.close(myLoop)

Keep in mind that you would need to check if the coroutine is Dead or not to stop it, because it will result in an Error.